0

There is i have :

public void SaveBitmapSourceToFile(string filePath, BitmapSource img)
    {
        BitmapEncoder encoder = new JpegBitmapEncoder();
        encoder.Frames.Add(BitmapFrame.Create(img));
        using (FileStream fileStream = new FileStream(filePath, FileMode.Create))
        {
            encoder.Save(fileStream);
        }
    }

I need to detect encoder.Save() finished so i can call another method that required my Jpg file

Sintex
  • 9
  • 1
  • In my experience, the `Save()` method does not return until it's written the file. Can you please provide a [mcve] that demonstrates whatever _problem_ you actually have? Also, you should double-check that you don't have other software on the system, such as anti-virus or indexing going on that would temporarily lock any newly-created file. – Peter Duniho Apr 02 '20 at 00:29
  • Does this thread help you somehow? https://stackoverflow.com/questions/5297076/wait-for-method-to-finish – Mike Apr 02 '20 at 09:14
  • @Mike Thanks sir. I did it in my own way! i tried to get file length and compare it with my last file length in while loop when they return `true` in `oldLength == newLength` loop will end and now i can call my other method i had errors cause my method needs that image but I/O was not write file completely, So loop ends when file was written and BOM! its work – Sintex Apr 02 '20 at 18:18

0 Answers0