kofucii
kofucii

Reputation: 7653

How to pause Asynchronous Method?

How can I pause Asynchronous Methods?

Upvotes: 2

Views: 667

Answers (2)

Brian Rasmussen
Brian Rasmussen

Reputation: 116401

You have several options: As @Darin points out, you can use Thread.Sleep, which is useful if you want to wait for a specific duration and not occupy the core in question while doing so. If you want to wait for a very short time Thread.SpinWait may be a better option, as you can avoid the context switch associated with Sleep. If you want to wait for a specific event, you can use an EventWaitHandle.

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1038850

Thread.Sleep in the worker method. Of course this would be a waste of thread resources because while it is paused it is not doing any useful work and threads are meant to do useful work :-)

Upvotes: 1

Related Questions