i have program like this
private void do_my_method_click(object sender, RoutedEventArgs e)
{
//there are some variables and methods here
//works fine
ThreadPool.QueueUserWorkItem(Start_method);
// when added gives error this thread owned by other thread
ThreadPool.QueueUserWorkItem(Start_method_2);
}
Start_method(object state)
{
}
Start_method_2(object state)
{
}
output of Start_method is used in Start_method_2 i dont know exactly where i am going wrong and i am a newbie for WPF and C#.
As @Tudor suggested, inside
Start_method_2you are modifying the GUI I think.Use
System.Threading.SynchronizationContext.Currentif you are modifying something on the UI which works on the main thread. Here is an example:This code is safe but it misses a lot (exception handling, etc.). Here is also another question for a similar issue which I suffered when I knew about threading a little:
Simple Async operation with Continuation scenario doesn't work on a WPF app