Why do modal dialogs opened through a menu item handle all window messages?

So, on the last day or so, I was fixing the error caused by the modal dialogue. I am working on an application that communicates with the server through a Windows message pump. When I use ShowDialog () to display a modal form, the message pump is blocked and none of my messages are processed, but they accumulate in the queue (expected behavior).

However, I recently noticed that if a modal form opens through a click event on a menu item, messages are pumped to the main form and processed. Does anyone know why these messages are not blocked when a modal form is displayed through a click event of a menu item?

EDIT: I should have noticed that I am using C #. How about this; if no one can answer this question, can someone tell me how to investigate it yourself? The only thing I can think of is to look at the call stack. Unfortunately, this hasnโ€™t told me anything yet.

+4
source share
6 answers

Yes, I call ShowDialog () from the click event of a menu item. In this case, the messages are pumped through the modal dialog to the main form.

+1
source

Try setting the same Owner / Parent for the dialog from the menu in the dialog box that displays the expected behavior of the messages.

+1
source

In general, your client interface should not block for long operations with the server .. Net makes the work very simple for the server to work using the BackgroundWorker stream. See this post for an example: Multithreaded imports.

An example is given in VB, but you can follow the links for a C # example.

+1
source

Are you calling ShowDialog () from a click event or in some other way?

0
source

What type of menu control are you using? Can it work on a separate thread with where the main form works?

0
source

@Chris: I just use the standard MenuStrip control. If it worked in a separate thread, then I would be interested in how it shows the form as modal. I experimented with showing a dialog from a separate thread so as not to block the message queue, but I cannot specify the main form as a parent, so it is not very modal.

0
source

Source: https://habr.com/ru/post/1277188/


All Articles