Tutorial :Synchronous calculation-heavy method call that doesn't prevent redrawing



Question:

Newbie C#/.NET threading question here:

Is it possible to have a synchronous (if that's the right term) method that doesn't return until it has finished some calculation but at the same time doesn't prevent the app from getting redrawn or going to "Not responding".

I guess the answer is probably threads but how does one make them part of a synchronous (if that's still the right term) method call rather than sending an event when done.

As an added requirement the code I'm adding this to does not have any dependencies on Winforms, it is designed to be run from a Console app or a Winforms app.

Thanks and sorry if this is a dumb question.


Solution:1

I assume that you want to block any user input while your calculation method is being executed. If so, this can be done with BackgroundWorker class. Set Enabled property of your form to false, perform all calculation logic in DoWork handler, and reenable form in RunWorkerCompleted handler.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »