Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set timeout feature for FileSystemWatcher?

Apologies if this question is too simple, I am new to the subject.

I am creating a few files, and need to wait until they are completed OR until some period of time has elapsed (this is what I call the timeout).

FileSystemWatcher is perfect for "wait until they are completed", but I cannot see a parameter that would govern its life span.

Using Tread.Sleep seems to defeat the purpose (?) - if its usage were correct, FileSystemWatcher would not exist, we would just Tread.Sleep while !File.Exists.

So, what is the easiest right way to implement it? Thanks.

like image 819
Yulia V Avatar asked Jun 07 '26 23:06

Yulia V


1 Answers

FileSystemWatcher.WaitForChanged Method

MSDN syas

A synchronous method that returns a structure that contains specific information on the change that occurred, given the type of change you want to monitor and the time (in milliseconds) to wait before timing out.

like image 182
Gopesh Sharma Avatar answered Jun 09 '26 11:06

Gopesh Sharma