John Walker John Walker - 3 months ago 7
C# Question

How can we do 2 or more process at a time.?

Can any body give a Good Example for parallel threading or multi Threading in c# .

for example when i am exporting a page from c# application it will take some time to complete so, mean while in that waiting time i want to do another exporting . how it will done in c#

Answer

You could use Task in .NET to achieve the parallel job, see more on https://msdn.microsoft.com/en-us/library/system.threading.tasks.task(v=vs.110).aspx

Here is a simple code for you

static void Main(string[] args)
{
    test1();
    Console.Read();
}

static void test1() 
{
    Task.Factory.StartNew(() =>
    {
        // Do the async job here
        Thread.Sleep(1000);
        Console.WriteLine("Done!");
    });
    Task.Factory.StartNew(() =>
    {
        // Another async job here
    });
    Console.WriteLine("Async Run...");
}

On your screen it will print out Async Run... first, then the Done! after a second