I have the following function and I'd like to use it within a System.Threading.Thread
:
private void tempFunction(int num, out string fullname, out string info)
{
// Doing a very long scenario.
// When finished, send results out!
fullname = result1;
info = result2;
}
I've tried to use the following code in (button_Click) event handler :
private void submit_Button_Click(object sender, RoutedEventArgs e)
{
string Fullname = string.Empty, Info = string.Empty;
int index = 132;
Thread thread = new Thread(() => tempFunction(index, out Fullname, out Info));
thread.Start();
thread.Join();
// I always use "MessageBox" to check if what I want to do was done successfully
MessageBox.Show(Fullname + "\n" + Info);
}
You can see that I use thread.Join();
because I need to wait untill the Thread finishes to get the result of the threaded process.
But the code above seems not working, it just freezes and I don't know why!
So I'm definitely doing something wrong, can you tell me how to do what I want?