c# - How can I show dialog on UI thread from another -


I am using Show.Dialog on multiple threads, but there is a problem. When the dialog box that was called from the UI thread closes, the main window is active, even when there are some dialog boxes that are called from another thread. To avoid this, I want to show the dialog boxes to another on the UI thread, but how is this possible? Or is there any other way for me to avoid this problem?

  Public partial class custom message box: window {// implements this method that automatically closes the window of the CustomMsgBox after the specified time Public CustomMsgBox collapsed (string message ) {InitializeComponent (); Owner = application Present. main window; // Many Essential Operations ...} Show Public Stable Zero (String Message) {var customMsgBox = New CustomMsgBox (Message); CustomMsgBox.ShowDialog (); }} Public Class Message Display {// Public Representative Zero MsgEventHandler (String Message) on UI Thread; Private Event MsgEventHandler MsgEvent = message = & gt; CustomMsgBox.Show (message); Private zero show message () {string message = "Some messages" Dispatcher.Invoke (MsgEvent, new object [] {message}); }} Public Class Error Monitor {// On Other Threads (Monitor Errors) Public Representative Zero Error: Event Handler (String Error); Private Event ErrorEventHandler error Event = error = & gt; CustomMsgBox.Show (error); Private listing & lt; String & gt; _Ros List = New List & lt; String & gt; (); Private zero show error message () {foreach (var error in _errorsList) {application Present. Dispatcher.BeginInvoke (error extortion, new object [] {error}); }}}  

When CustomMsgBox called from the UI thread automatically turns off, the main window is activated even when certain custom message boxes are also called from the monitoring thread .

You should only open the dialog from the UI thread. You can invite UI-threads with Dispatcher: Call it instead of

  // Dialogue Direct Ent Thread. Dispatch. Invoke (Action) representative () {// here you can show your dialogue});  

You can type your own ShowDialog / Show method, and then call the dispatcher.

I hope that I think your question is right.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -