Please see my comments to the question.
One approach alternative to the
is using preliminary created thread, created through the constructor, which you can keep sleeping (wasting no CPU time for that, of course) and activate when the task is fed to it. This is a really good and stable variant of design, because you allocate all related resources only in the very beginning of runtime. Such throttling
is done by the class
You just reset or signal the event thread handle, and the thread calling its method
is put to the wait state of the event handle is non-signaled. The thread will be awaken when it is signaled or by some other conditions (abort or timeout).
One more specialized form of such behavior with zero-waste CPU can be achieved with the blocking queue
. Please see my article on the topic:
Simple Blocking Queue for Thread Communication and Inter-thread Invocation
As you can see, one kind of items you can feed to the queue could be delegate instances
. This way, you can immediately feed tasks to the thread, and the thread will be waiting for the task, wasting no CPU time in the wait state. (And this is possible because threading is done based on interrupts
By the way, this is how invocation of the delegate instances to some UI thread is working with
, which brings us to other problem: how to work with UI from some non-UI thread?
You cannot call anything related to UI from non-UI thread. Instead, you need to use the method
(for both Forms or WPF) or
You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()
Problem with Treeview Scanner And MD5
Now, I promised to suggest thread wrapper and motivate it. Please read my past answers:
Thread wrapper with lock: multithreading use
Thread wrapper with event
See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net
Control events not firing after enable disable + multithreading