Q:

Non-locking sleep/waitfor/delay function for ASP.NET

I am writing an ASP.NET class that interfaces with an external application. The flow of the transaction between the web server and this application is as follows:

My object writes a file to a directory.
The outside application detects this file and processes it. This can take between 1-5 seconds.
The outside application writes a response file to the same directory.
My object detects the response file and parses the results.

The 1-5 seconds it can take for the external application to process my file is my problem. The most straightforward way to wait for the file seems to be something like this:
Do While Not File.Exists(f)
    Thread.Sleep(500)
Loop

Of course, Thread.Sleep() completely locks up the rest of my website until the outside application processes the file. Clearly, this is not a workable solution.
How can I effectively "wait" for my file to be processed without locking up the rest of my website?

A:

Use the FileSystemWatcher - when a file will be created it will fire an event that you can subscribe to.

