0

I have a C# Winforms UI that makes a call to a COM object to derive some data.

I want a progress bar on the UI to cycle in order to indicate that work is in progress. Problem is that the COM call is synchronous, so processing waits for the COM call to complete and thus the progress bar cycling code does not get called.

Should I: 1. Make the COM call asynch to allow the progress bar code to cycle? 2. Use a second thread to run the progress bar (will this work or will the UI thread still be hung up on the COM call and thus not refresh the progress bar?) 3. some cleverer method?

Dave Tapson
  • 810
  • 1
  • 9
  • 22
  • 1
    Refer this http://stackoverflow.com/questions/1952201/display-progress-bar-while-doing-some-work-in-c – Techidiot Oct 03 '16 at 08:41
  • You can only ever display progress when you get feedback about progress. Without that it is just a blind guess how you should move the progress bar. You don't have that so you could, at best, use ProgressBarStyle.Marquee. Basic "I'm not dead" feedback that is not enormously more helpful than an hourglass cursor. Also very important to create the COM component on another thread so it cannot block your UI, a plain worker thread is not good enough, that needs to [look like this](http://stackoverflow.com/a/21684059/17034). – Hans Passant Oct 03 '16 at 08:56

1 Answers1

1

You should create separate thread for execution of method call which takes time. Until it returns required data, show progress bar on your UI thread. This should work fine.

i.e. You should select first option from suggested three.

Kamalesh Wankhede
  • 1,475
  • 16
  • 37