Long running tasks are done using threads, not timers. The only one little problem with having some extra thread performing such a long running task under the UI is that you cannot directly operate UI from that thread. This problem is solved using UI thread invocation mechanism.
You cannot call anything related to UI from non-UI thread. Instead, you need to use the method
Invoke
or
BeginInvoke
of
System.Windows.Threading.Dispatcher
(for both Forms or WPF) or
System.Windows.Forms.Control
(Forms only).
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[
^].
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[
^].
Now, it's most convenient to create a permanent thread and throttle it by using a event wait handle. Also, it is very convenient to encapsulate all that and also all synchronization and invocation mechanisms in a thread wrapper. This way, the thread can be reused as tasks are coming up. Please see my past answers:
Making Code Thread Safe[
^],
Running exactly one job/thread/process in webservice that will never get terminated (asp.net)[
^],
pause running thread[
^],
ManualResetEvent and AutoResetEvent in Thread[
^].
On the thread wrappers, see also:
How to pass ref parameter to the thread[
^],
Change parameters of thread (producer) after it is started[
^],
MultiThreading in C#[
^].
Also, you can use a blocking queue for pushing some tasks to the thread wrapper (then the even thread handler is not needed, it is encapsulated in the queue, which can be a queue of delegate instances representing those tasks directly). This is explained in my article:
Simple Blocking Queue for Thread Communication and Inter-thread Invocation[
^].
With .NET v.4 and later, you can use faster blocking queue already implemented in .NET FCL:
http://msdn.microsoft.com/en-us/library/dd267312%28v=vs.110%29.aspx[
^].
—SA