views:

70

answers:

1

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.

+1  A: 

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.

Anton Gogolev
BackgroundWorker is from System.ComponentModel, which has nothing to do with WinForms.
Anton Gogolev