开发者

Thread wait on file input pattern

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜