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.


Recommended Answers

All 3 Replies

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))
   //Stuff here will run in parallel with the thread we just started
void myParallelMethod()
   while (!bKillThread)
       Thread.Sleep(500); //Pause for 500 ms to avoid overloading cpu
void CallbacktoMainThread()
   //thread safe checking
   if (InvokeRequired) Then
      Invoke(new myCallBackDelegate(CallbacktoMainThread))

Thank you Skata, I will look at this over the weekend and come back to you :)

Sorry for the delayed reply, that has worked perfectly thanks, problem solved :)

Be a part of the DaniWeb community

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