开发者

Thread wait on file input pattern

开发者 https://www.devze.com 2023-01-31 16:31 出处:网络
What\'s the normal pattern for a thread to wait for file input in C# when it reaches end of file and

What's the normal pattern for a thread to wait for file input in C# when it reaches end of file and needs to wait. Any p开发者_开发技巧articularly way of coding it, which is neat and elegant.

Thanks. Bob.


Not really a pattern but the FileSystemWatcher (http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx) might come in handy.


I will be interested in seeing what the other answers are. I have not found an elegant solution. Here is what I have done in the past.

  1. Have the reader try to open the file exclusively. This will fail if the file is open elsewhere.
  2. Have a retry loop....sleep X milliseconds...retry Y times. Usually, I pull X & Y out into a configuration file.

Hope this helps.

Bob

0

精彩评论

暂无评论...
验证码 换一张
取 消