How do I thread a simple method and return its results?
For example, I have a class called Math, a single method that takes two ints as params and returns a int result. How do I thread this and get the result to be used later in the application?
Thread thread = new Thread(() => m.SumTest(5));
thread.Start();
public class Maths
{
public int num1;
public int num2;
Random r = new Random();
public void Divide()
{
for (int i = 0; i < 100000; i++)
{
num1 = r.Next(1, 2);
num2 = r.Next(1, 2);
int result = num1 / num2;
Console.WriteLine(result);
num1 = 0;
num2 = 0;
}
}
public int SumTest(int max)
{
int answer = 0;
for (int i = 0; i < max; i++)
{
answer += i;
}
return answer;
}
}