等待句柄应当是你进行多线程编程的必备装备。由于我们的主要兴趣点在于Silverlight多线程编程相关的内容,所以我们不想再深入探讨WaitHandle。但在此为你提供一个典型的例子,告诉你使用WaitHandle的基本方法。
清单1:
public partial class MainPage : UserControl{
AutoResetEvent handle = new AutoResetEvent(true);
public MainPage()
{
InitializeComponent();
new Thread(() =>
{
while (true)
{
handle.WaitOne();
this.Dispatcher.BeginInvoke(() =>
{
this.TextBlock1.Text = DateTime.Now.ToString();
});
}
}).Start();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
handle.Set();
}
664

被折叠的 条评论
为什么被折叠?



