Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - backgroundworker wait for file to be created

I have a backgroundworker.. In the backgroundworker_doWork I would like to check if a file exists or not.. if doesn't then i wait for the file to be create and once its create then carry on with the work its suppose to do

I want do something like this.. but i just figure out how to do it.. im new to this :

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
    if(File.Exists(filename)){
        //.. code to do my work ...
    }
    else{
        //..Wait for the file to be create...
    }
//... end of backgroundworker
}

Thanks in advance

like image 958
Fahad.ag Avatar asked Dec 27 '22 03:12

Fahad.ag


1 Answers

You can use a FileSystemWatcher to get an event when the file is created.

like image 166
BrokenGlass Avatar answered Jan 12 '23 16:01

BrokenGlass