简体   繁体   English

用于处理的线程块

[英]Thread block for processing

I'm coding a C# wpf app and I need to block processing in order to wait for an event.我正在编写 C# wpf 应用程序,我需要阻止处理以等待事件。 If I use Thread.Sleep() the event is never triggered, the UI also hangs, so I don't know what else to do.如果我使用 Thread.Sleep() 事件永远不会触发,UI 也会挂起,所以我不知道还能做什么。

switch (process.Action)
            {
                case 1:
                    this.Goto(process.VarValue);
                    break;

                case 2:
                    this.Extract(process.VarKey, process.VarValue);
                    break;

                case 3:
                    this.Validate(new string[] { });
                    break;

                default:
                    break;
            }

Like for "extract" case, it grabs information and sends event to service which opens another WPF window, which pops up, asking user for input.与“提取”案例一样,它获取信息并将事件发送到服务,从而打开另一个 WPF window,它会弹出,要求用户输入。

The UI shows, but submit button hangs, and then the application hangs, im using unity, and eventaggregator, also Magellan for wpf, so the project is getting more and more complex. UI显示,但提交按钮挂起,然后应用程序挂起,我使用unity和eventtaggregator,还有wpf的Magellan,所以项目越来越复杂。

I am trying for a simpler method for the thread to wait, for the user input.我正在尝试一种更简单的方法让线程等待用户输入。

Please advise.请指教。

  1. thread starts => switch线程开始 => 切换
  2. on extract case => sends event to pop up service opens (wpf window, for user input)在提取案例 => 发送事件以弹出服务打开(wpf window,用于用户输入)
  3. i am using thread.sleep(1000) till the service sends response EVENT我正在使用 thread.sleep(1000) 直到服务发送响应事件
  4. but the application hangs, on using thread.sleep including the (pop up window).但应用程序挂起,使用 thread.sleep 包括(弹出窗口)。
  5. I want to wait for the user input on the main thread.我想在主线程上等待用户输入。

Use Window.ShowDialog to open your pop up window.使用Window.ShowDialog打开您的弹出窗口 window。 Showdialog will return only after the pop has been closed again.只有在弹出窗口再次关闭后,Showdialog 才会返回。 See here .这里 No need for complex threading scanario's.不需要复杂的线程扫描。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM