-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion to use My.Application.DoEvents is irresponsible. #34917
Comments
Hey @Darkicorn, thanks for addressing this. A somewhat problematic scenario can occur, when there is a long-running task which runs on the UI thread, probably triggered by a typical WinForms Now, this of course blocks the further processing of the UI-Thread. And that means after a couple of seconds, the App becomes unresponsive, and yes, that's bad. So, what folks often do to mitigate, is this: And with that they are introducing a potential and unintended recursion. Users of the app may hit the button repeatedly. And with that, they are queuing in more the button click events, which are (indirectly) called from the still executing button click event handler method, and so on, and so on. This is certainly an improvable design. Things to mitigate that:
In all the cases, the UI controls would need to be guarded against multiple clicks. @Darkicorn, did you have other scenarios in mind? Thanks, Klaus |
Thanks for the added clarification @KlausLoeffelmann I'll add this to our backlog as an enhancement. I'll also add the "help wanted" label in case anyone wants to submit a PR before we update it. |
Hey @BillWagner can I work on this issue ? It would be great if you could elaborate on how to fix this issue. |
Hi @Adi9235 Thanks for volunteering to work on this. @KlausLoeffelmann 's comment #34917 (comment) provides the background to address this. The core problem is that |
I don't agree with
But I do agree with
The example in the article isn't well written. And the headings seem odd. Example 1 doesn't actuallk contain an example. Further, there are details that should be in the main portion of the article, such as where you can declare events and use Another problem is that it's written in the context of Windows Forms and not just in the context of VB the language. The UI stack doesn't matter when talking about the |
I will try to fix this issue and will make the PR soon |
Definitely +1 to what @adegeo said. We should see though, that we add this warning where it actually belongs, so in the WinForms app space. But I guess it's not too much of a high priority. |
Yes, the WinForms docs should have something about DoEvents, the caveats, dangers, and proper scenarios. Here is a good thread about it: https://stackoverflow.com/questions/11352301/how-to-use-doevents-without-being-evil I created this issue to track it: dotnet/docs-desktop#1647 |
I use DoEvents all the time. But having been a Windows C/C++ developer, I understand how message pumps work. To say its irresponsible is to say its irresponsible for a Marine to carry a gun. Yes, reentrancy is an issue, but know what your doing and its a helpful tool. |
It is irresponsible to show an example with My.Application.DoEvents - at the very least the note saying "don't use it" should come before the example. Preferably the example should be re-written to eliminate it. (It's an issue that's been going on for more than twenty years, so it might as well be fixed now.)
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: