What i\'m trying to create is a background worker that executes a few processes every 30seconds. But I want this while loop to execute for as long as the program is launched.
Are you looking for
while(true)
I agree with Bobby that a System.Threading.Timer (or a System.Timers.Timer) is probably best suited to this job.
But if you must create a use a worker thread, I'd rather create one specially for the task. Running a BackGroundWorker (which is a ThreadPool Thread) is a while loop for the lifetime of your application doesn't sit well with me.
Maybe something like this:
private void watcherprocess1()
{
Thread thread = new Thread(new ThreadStart(this.Work));
thread.IsBackground = true;
thread.Name = "My Worker.";
thread.Start();
}
private void Work()
{
while(true)
{
specficView2();
makeFormlist2();
populateListview2();
Thread.Sleep(30000);
}
}
I think a Timer from the Threading-Namespace would be much better suited for this. It will tick asynchron, and you can spawn of the process from the Tick-Event.
Use System.Windows.Forms.Timer