Thread
-
Hello I am doing C#.NET application.I want to run a background process until my application exit.How can I implement the above using thread.
Like this:
using System;
using System.Threading;namespace BackgroundThread
{
class Program
{
static void Main(string[] args)
{
Thread t = new Thread(BackgroundMethod);
t.IsBackground = true;
t.Start();
Console.ReadLine();
}private static void BackgroundMethod() { while (true) { Thread.Sleep(1000); Console.WriteLine("Tick"); } } }
}
Regards, Rob Philpott.
-
Hello I am doing C#.NET application.I want to run a background process until my application exit.How can I implement the above using thread.
-
Try using BackgroundWorker component which u can find in ToolBox of Visual Studio.
Krishnraj
BackGroundWorkers are for forms though, maybe his program doesn't have a form. Though, if you use a form, the BackGroundWorker is the easiest way to go. Just remember to lock any objects while they're being worked on, but beware of dealocks (more than one thread locking the same object).