dansays
dansays

Reputation: 2779

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:

  1. My object writes a file to a directory.
  2. The outside application detects this file and processes it. This can take between 1-5 seconds.
  3. The outside application writes a response file to the same directory.
  4. 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?

Upvotes: 0

Views: 776

Answers (1)

Oded
Oded

Reputation: 499092

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

Upvotes: 2

Related Questions