Milan Solanki
Milan Solanki

Reputation: 1207

Thread block for processing

I'm coding a C# wpf app and I need to block processing in order to wait for an event. If I use Thread.Sleep() the event is never triggered, the UI also hangs, so I don't know what else to do.

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.

The UI shows, but submit button hangs, and then the application hangs, i m using unity, and eventaggregator, also Magellan for wpf, so the project is getting more and more complex.

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)
  3. i am using thread.sleep(1000) till the service sends response EVENT
  4. but the application hangs, on using thread.sleep including the (pop up window).
  5. I want to wait for the user input on the main thread.

Upvotes: 0

Views: 266

Answers (1)

Edwin de Koning
Edwin de Koning

Reputation: 14387

Use Window.ShowDialog to open your pop up window. Showdialog will return only after the pop has been closed again. See here. No need for complex threading scanario's.

Upvotes: 1

Related Questions