Farthest Shore
Farthest Shore

Reputation: 279

Delay execution in a separate thread ASP.NET C#

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

Answers (1)

axel_c
axel_c

Reputation: 6796

Sleeping in the thread is fine.

Since there is nothing else going on and you don't care about the results or synchronisation, best approach is to KISS.

Upvotes: 2

Related Questions