Hi,

I have three functions, a(), b() and c().

In function a() I need to call function b() and then after a 2 second delay call function c().

However, I can't use Thread.sleep(2000) as I need to be able to keep clicking on other buttons.

I think I need to use Threads a bit more, but I can't see how to delay the thread from starting
Thanks for any and all help.

Andrew.

Recommended Answers

When you create a thread you create it with a callback delegate and when you want to start it you call thread.Start() with an optional object as a parameter for information you want to pass to the thread.

If this operation is really as simple as you have indicated …

Jump to Post

A backgroundworker uses a thread... its really just a "drag and drop" version of a simple thread. Unless you're writing very processor intensive code then you don't need to worry about the overhead difference. If i'm working on a form and doing something simple I usually pick the background worker

Jump to Post

All 7 Replies

When you create a thread you create it with a callback delegate and when you want to start it you call thread.Start() with an optional object as a parameter for information you want to pass to the thread.

If this operation is really as simple as you have indicated it is then you could use a BackgroundWorker to execute in the background. It supports reporting progress and a finished event. You can drop one on your form from the toolbox and wire up the events to call a() b() and c() and call Thread.Sleep(2000); inside of it since it is not running on the thread that paints your GUI, so you can keep clicking buttons.

Background worker! Brilliant!

I have just (before I read your post) managed to do it with a thread, starting a new thread and having Thread.sleep(1000) as the first line of the function called for the thread.

Which is "better"? I don't understand the differences between backgroundworker and a thread.

Thanks again.

Andrew.

A backgroundworker uses a thread... its really just a "drag and drop" version of a simple thread. Unless you're writing very processor intensive code then you don't need to worry about the overhead difference. If i'm working on a form and doing something simple I usually pick the background worker

Thanks. This worked brilliantly.

I'm glad you got it working

Please mark this thread as solved if you have found an answer to your original question and good luck!

I know this has been handled... but after reading through, why go so complicated? why not just use a timer control?

seems odd to create a new thread for the sole purpose of sleeping it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.