Reputation: 15175
Can Application.DoEvents()
ever be a viable solutions with forms where processing is intensive on the main window thread?
Upvotes: 3
Views: 592
Reputation: 61686
Can Application.DoEvents() ever be a viable solutions with forms where processing is intensive on the main window thread?
It can never be. You could disable the UI to prevent re-entrancy, but that would be a very user-unfriendly step, as the user won't be able to cancel the operation or close the app. Here is a great explanation of the implications: "Keeping your UI Responsive and the Dangers of Application.DoEvents".
Here you could find an example of how to offload CPU-intensive work to a pool thread, with progress updates and cancellation support.
There are may be cases when you have to stay on the same thread while doing the processing. E.g., you might be coding some real-time syntax highlighting or spell-check logic for an editor control.
For such cases, you can built your logic using timer events, idle events and/or async/await
. This and this would be related then.
Upvotes: 7