public partial class MainWindow : Window
{
private Thread t;
private delegate void UpdateLog(string msg);
public MainWindow()
{
InitializeComponent();
}
private void Window_ContentRendered(object sender, EventArgs e)
{
t = new Thread(appendToLog);
t.IsBackground = true;
t.Start();
}
private void appendToLog()
{
for (int i = 0; i < 10; i++)
{
Dispatcher.Invoke(new UpdateLog(UpdateLogMethod), new object[] { "Message #" + i.ToString() + Environment.NewLine});
Thread.Sleep(1000);
}
}
private void UpdateLogMethod(string msg)
{
tbLog.AppendText(msg);
}
}
|