Reputation: 279
In a ASP.NET C# web application I want to perform an asynchronous action after a form has been submitted. It's fire and forget. I don't need to wait for a response of any kind.
I can do that as follows:
System.Threading.ThreadPool.QueueUserWorkItem(delegate { TheThingToDo(); });
Now, within my TheThingToDo() method I would like to introduce a delay of, say, 10 seconds before everything kicks off. The simplest thing seem to be to use thread.sleep since I'm in a separate thread already and don't care about execution being blocked.
Is there any reason not to do this? Or is there a more elegant solution? I've looked at timers but using them seems to introduce more code for not much benefit in this particular case?
Upvotes: 0
Views: 308