"WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" 350" 525" WindowStartupLocation="CenterScreen" Loaded="Window_Loaded">
"Stretch" Margin="12" Name="richTextBox1" VerticalAlignment="Stretch" />
1 private void Window_Loaded(object sender, RoutedEventArgs e)
2 {
3 //创建线程1
4 Thread t1 = new Thread(new ThreadStart(T1));
5 t1.Start();
6
7 //创建线程2
8 Thread t2 = new Thread(new ThreadStart(T2));
9 t2.Start();
10 }
///
/// 线程1调用函数
/// add by
///
private void T1()
{
while (true)
{
Thread.Sleep(TimeSpan.FromSeconds(1));
ShowMsg(string.Format("T1 {0}", System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss:fff")));
}
}
///
/// 线程2调用函数
/// add by
///
private void T2()
{
while (true)
{
Thread.Sleep(TimeSpan.FromSeconds(1));
ShowMsg(string.Format("T2 {0}", System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss:fff")));
}
}
private void ShowMsg(string sMsg)
{
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate() {
richTextBox1.AppendText(string.Format("{0} \r\n",sMsg));
});
}