.NET下多线程中设置按钮的文本
Windows:
delegate void DelegateSetValue(Button btn, string value);
private void TheTime()
{
DelegateSetValue d = new DelegateSetValue(SetValue);
btnSearch.Invoke(d, btnSearch, "忙**");
Thread.Sleep(1000);
btnSearch.Invoke(d, btnSearch, "搜索");
}
private void SetValue(Button btn, string value)
{
btn.Text = value;
}
WPF:
private delegate void DelegateSetValue(Button btn, string value);
private void TheTime()
{
Delegate d = Delegate.CreateDelegate(typeof(DelegateSetValue),this,"SetValue");
btnSearch.Dispatcher.Invoke(DispatcherPriority.Normal, d, btnSearch, "忙..");
Thread.Sleep(1000);
btnSearch.Dispatcher.Invoke(DispatcherPriority.Normal, d, btnSearch, "搜索");
}
private void SetValue(Button btn, string value)
{
btn.Content = value;
}
Silverlight:
delegate void DelegateSetValue(Button btn, string value);
private void TheTime()
{
DelegateSetValue d = new DelegateSetValue(SetValue);
btnSearch.Dispatcher.BeginInvoke(d, btnSearch, "忙--");
Thread.Sleep(1000);
btnSearch.Dispatcher.BeginInvoke(d, btnSearch, "搜索");
}
private void SetValue(Button btn, string value)
{
btn.Content = value;
}
delegate void DelegateSetValue(Button btn, string value);
private void TheTime()
{
DelegateSetValue d = new DelegateSetValue(SetValue);
btnSearch.Invoke(d, btnSearch, "忙**");
Thread.Sleep(1000);
btnSearch.Invoke(d, btnSearch, "搜索");
}
private void SetValue(Button btn, string value)
{
btn.Text = value;
}
WPF:
private delegate void DelegateSetValue(Button btn, string value);
private void TheTime()
{
Delegate d = Delegate.CreateDelegate(typeof(DelegateSetValue),this,"SetValue");
btnSearch.Dispatcher.Invoke(DispatcherPriority.Normal, d, btnSearch, "忙..");
Thread.Sleep(1000);
btnSearch.Dispatcher.Invoke(DispatcherPriority.Normal, d, btnSearch, "搜索");
}
private void SetValue(Button btn, string value)
{
btn.Content = value;
}
Silverlight:
delegate void DelegateSetValue(Button btn, string value);
private void TheTime()
{
DelegateSetValue d = new DelegateSetValue(SetValue);
btnSearch.Dispatcher.BeginInvoke(d, btnSearch, "忙--");
Thread.Sleep(1000);
btnSearch.Dispatcher.BeginInvoke(d, btnSearch, "搜索");
}
private void SetValue(Button btn, string value)
{
btn.Content = value;
}