Hi all,

I am looking to have a long process running in the background to my main form with a timer ticking on the main form animating the elipsis on the end of some text.

Was looking for some insight into the best way to go about this and any decent resources worth reading on the subject, or a starter.

Im aware of the BackgroundWorker class so im assuming this will be used but implementation is where im falling down.

Cheers,

Look into the System.Threading.Thread class and the System.Threading namespace to run code in parallel.

.Net 3.5 and up also have something called a TaskFactory, which handles a lot of the overhead and complications that can arise when making multithreaded apps. I typically do all the threading myself, but my cooworkers swears by the TaskFactory.

Keep in mind that if you access something on one thread at the same time as on a different thread you will have big problems (cross threading violations, race conditions, and other unexpected results).

Here's a simple example of a multithreaded app using System.Threading.Thread.

volatile bool bKillThread = false;
delegate void myCallBackDelegate();
void StartNewThread()
{
   Thread t = new Thread(new ThreadStart(myParallelMethod))
   t.Start();
   //Stuff here will run in parallel with the thread we just started
}
void myParallelMethod()
{
   while (!bKillThread)
   {
       CallbacktoMainThread();
       Thread.Sleep(500); //Pause for 500 ms to avoid overloading cpu
   }
}
void CallbacktoMainThread()
{
   //thread safe checking
   if (InvokeRequired) Then
      Invoke(new myCallBackDelegate(CallbacktoMainThread))
   else
      DoSomething(); 
}

Edited 4 Years Ago by skatamatic: n/a

This question has already been answered. Start a new discussion instead.