WPF vs WinForm 多线程UI跟新问题
写了个小小的测试程序,在Winform分别加了一个Winform的ProcessBar和WPF的ProcessBar,再加一个button, 下面是button Click事件的代码:
private void button1_Click(object sender, EventArgs e) { mWinformProgressBar.Value = 0; mWPFProcessBar.Value = 0; double d = 0.0f; for (int i = 0; i < 1000; i++) { for (int j = 0; j < 100000; j++) { d = (double)i / (j + 1); } mWinformProgressBar.Value += 1; mWPFProcessBar.Value += 1; } }public void DoEvents(){ DispatcherFrame frame = new DispatcherFrame(); Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(delegate(object f) { ((DispatcherFrame)f).Continue = false; return null; } ), frame); Dispatcher.PushFrame(frame);}