0

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?

2
  • 1
    Sleep is proper, Timer is just a wrapper for new thread as well and most likely using Sleep as well behind the scenes. Commented Feb 26, 2013 at 11:52
  • 1
    I've done it myself (use Thread.Sleep in this situation), so I hope there's no reason not to... Commented Feb 26, 2013 at 11:59

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.