111,126
社区成员
发帖
与我相关
我的任务
分享
public class WpfApplication
{
private static DispatcherOperationCallback exitFrameCallback = new DispatcherOperationCallback(ExitFrame);
public static void DoEvents()
{
DispatcherFrame nestedFrame = new DispatcherFrame();
DispatcherOperation exitOperation = Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, exitFrameCallback, nestedFrame);
Dispatcher.PushFrame(nestedFrame);
if (exitOperation.Status != DispatcherOperationStatus.Completed)
{
exitOperation.Abort();
}
}
private static Object ExitFrame(Object state)
{
DispatcherFrame frame = state as DispatcherFrame;
frame.Continue = false;
return null;
}
}
private void button_Click(object sender, RoutedEventArgs e)
{
button.IsEnabled = false;
WpfApplication.DoEvents();
i++;
button.Content = i.ToString();
System.Threading.Thread.Sleep(2000);
button.IsEnabled = true;
}
private void button_Click(object sender, RoutedEventArgs e)
{
System.Threading.Thread.Sleep(2000);
MessageBox.Show("M");
}