At the most basic level you can use a new Thread, or you can use BackgroundWorker, it all depends on what level of communication and control you need between the main thread and the child thread. Multi-threading is a fairly indepth subject so you might need to read up about it. Most problems with multi-threading involve synchronising the threads, or one thread telling another thread to stop running, when you need to "join" the other thread etc. Here is a very basic example though.
public static void DoSomething()
{
for (int i = 0; i < 5; i++)
{
Thread.Sleep(500);
Console.WriteLine("DoSomething {0}", i);
}
}
public static void task(string[] args)
{
Thread t = new Thread(new ThreadStart(DoSomething));
t.Start();
string str = "";
for (;;)
{
for (int i = 0; i < 3; i++)
{
str += ".";
Console.Write("\rPerforming Some Task{0} ", str);
if (i <= 2)
Thread.Sleep(1000);
if (i == 2)
{
Console.Write("\b\b\b ");
str = "";
}
}
}
}
Here is a solution that keeps all processing on child threads
class Program
{
private static bool running = false;
static void Main(string[] args)
{
Thread t = new Thread(new ParameterizedThreadStart(task));
t.Start(args);
Console.ReadLine();
running = false;
t.Join();
}
public static void DoSomething()
{
for (int i = 0; i < 5; i++)
{
Thread.Sleep(500);
Console.WriteLine("DoSomething {0}", i);
}
}
public static void task(object a)
{
running = true;
string[] args = (string[])a;
Thread t = new Thread(new ThreadStart(DoSomething));
t.Start();
string str = "";
while (running)
{
for (int i = 0; i < 3; i++)
{
str += ".";
Console.Write("\rPerforming Some Task{0} ", str);
if (i <= 2)
Thread.Sleep(1000);
if (i == 2)
{
Console.Write("\b\b\b ");
str = "";
}
}
}
}
}