using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Threading; namespace AddDelete { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { Thread thread = null; ThClass objThClass = null; public MainWindow() { InitializeComponent(); } private void button1_Click(object sender, RoutedEventArgs e) { for (int i = 1; i <= 10; ++i) { treeView1.Items.Add(i.ToString()); } objThClass = new ThClass(); if(null == thread) thread = new Thread(new ThreadStart(objThClass.TestMethode)); thread.Start(); objThClass.Changed += TempHandler; } private void button2_Click(object sender, RoutedEventArgs e) { treeView1.Items.Clear(); } public void TempHandler(object sender, EventArgs e) { try { //treeView1.Items.Clear(); treeView1.Items.Add("Temp1"); thread.Abort(); thread = null; } catch (Exception exp) { Console.WriteLine(exp); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace AddDelete { public delegate void ChangedEventHandler(object sender, EventArgs e); class ThClass { public event ChangedEventHandler Changed; public void TestMethode() { // Do some task (DB operation) // On task complete Changed(this, null); } } }
See my solution here:
thread.Abort();
treeView1.Items.Add("Temp1");
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)