Bikswan
Bikswan

Reputation: 140

Running Long Process on UI Thread and still update UI to report the progress

I have C# application which has to process the long job. I have some restriction because of which I cannot afford to run that long job in the background thread for e.g. some of the com objects I am using cannot be used in the background thread. How can I have this long job processed in UI thread and have the UI updated with progress report.

Can anything be done on this to make UI responsive while processing the big job?

Thanks in advance,

Bibek Dawadi

Upvotes: 1

Views: 943

Answers (2)

Allon Guralnek
Allon Guralnek

Reputation: 16131

If that job is not one big blocking call, and you're using WinForms, you can call Application.DoEvents()from within your long running operation. Every time you call it, the UI will update (all pending window messages will be processed), so call it as often as you want your UI to respond.

Upvotes: 0

user180326
user180326

Reputation:

You can use COM objects from background threads. Just make sure that the background thread is also an STA thread. (assumption: COM object is an STA object itself).

On Vista Aero and later, Windows will make strange decisions if you don't paint your windows quickly enough. Like that it will start displaying old versions of the window contents. This will start if your window is not responding to paint messages for a second or two.

Upvotes: 2

Related Questions