【发布时间】:2014-01-20 15:52:43
【问题描述】:
好的,所以我有一个 WPF 应用程序,它在按下按钮时会运行如下测试列表:
- 在 GUI 中按下 RunTest 按钮
- BackgroundWorker 已创建并开始运行 DoWork(见下文):
-
当 t.Name == "TestSpecial" 时,我想在继续之前在 UI 中显示图像。在我继续之前显示图像至关重要。
DoWork(...) { List<Test> tests = .... for (Test t in tests) { switch(t.Name) { case "Test1": //Do something break; case "Test2": //Do something else break; ... case "TestSpecial": // Here I want to: // 1. Tell UI to show an image on the screen // 2. Wait for the image to show up // 3. Continue with my test break; case "TestN+1": //Do something completly different break; } } }
我可以使用Dispatcher.InvokeAsync 或类似的方法来显示图像,但有什么方法可以等待它完成或以其他方式保证图像在继续之前显示?
【问题讨论】:
-
为什么不使用像 Coded UI 这样的实际 UI 测试框架?
-
您可以在后台运行所有测试,显示进度并可以取消。这种等待某事的方式不是问题。否则,您必须以某种方式停止测试(完全退出
DoWork)并仅在显示图像(事件?)后继续(再次输入)。 -
@ DanielMann 在这种情况下,它不是关于测试 UI,应用程序本身正在使用相机测试硬件。 @Bolu Thx,会调查的。
-
你怎么知道“图像正在显示”?
标签: c# wpf multithreading backgroundworker