I have an application where a thread is used to calculate a bunch of numbers but the problem is that the application finishes before the Thread completes the calculation and returns the calculated number. What's the way of making the application wait until the calculation is done?
Here's my code:
namespace ThreadWaiting
{
class Program
{
public static int number=0;
public static void Main(string[] args)
{
Thread t = new Thread(Calculate);
t.Start();
//Wait here until processed?
Console.WriteLine(number);
Console.ReadKey();
}
private static void Calculate(object obj)
{
number = 2 + 2;
}
}
}
If you run that, you will see that it prints "0" and not "4".
Any ideas guys? Thanks!