I'm trying to write a Windows Form app that calculate the prime factorization of numbers smaller than 10^20. But with numbers bigger than 10^12, the app start to freeze a few second before giving the result. So I tried to create a thread to calculate the answer separately. Here's the code:
class fact
{
static long[] res = new long[202];
static long num;
public static string output;
static void calcFact(long n)
{
//calculate prime factorization into array res
}
static void call()
{
calcFact(s);
}
public static void execute(string input)
{
s = long.Parse(input);
ThreadStart childref = new ThreadStart(call);
Thread childThread = new Thread(childref);
childThread.Start();
for (int i = 0; i < len; i++) output += res[i].ToString() + " ";
}
}
private void InputBox_TextChanged(object sender, EventArgs e)
{
if (InputBox.Text != "")
{
fact.execute(InputBox.Text);
output.Text = fact.output;
}
}
Without creating a new thread, the app work, but now the output is always empty. Can someone explain how did this thread run and how to fix it?