private void button1_Click(object sender, RoutedEventArgs e) { OnTaskCompleteDelegate callback = new OnTaskCompleteDelegate(OnTaskComplete); disableButtons(); stopwatch.Reset(); stopwatch.Start(); Task.Run(() => { ThreadPoolProcess(); stopwatch.Stop(); int current_thread_id = Thread.CurrentThread.ManagedThreadId; //Accessing UI this.Dispatcher.Invoke(() => { callback("Task completed successfully\n Task thread ID: " + current_thread_id + "\n Watch ticks: " + stopwatch.ElapsedTicks); }); //Console.WriteLine("Task thread ID: {0}", Thread.CurrentThread.ManagedThreadId); }); }
private void button2_Click(object sender, RoutedEventArgs e) { OnTaskCompleteDelegate callback = new OnTaskCompleteDelegate(OnTaskComplete); disableButtons(); stopwatch.Reset(); stopwatch.Start(); //ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadPoolProcess)); ThreadPool.QueueUserWorkItem(o => { ThreadPoolProcess(); stopwatch.Stop(); //Accessing UI this.Dispatcher.Invoke(() => { callback("Threadpooling completed successfully" + "\n Watch ticks: " + stopwatch.ElapsedTicks); }); }); }