I will go with the first choice here with some changes:
First, run a possible lengthy operation on different threads.
Then start another thread to check the first status using the wait descriptor with a timeout to wait for it to complete. if timeout triggers show a progress bar.
Sort of:
private ManualResetEvent _finishLoadingNotifier = new ManualResetEvent(false);
private const int ShowProgressTimeOut = 1000 * 3;
private void YourLongOperation()
{
....
_finishLoadingNotifier.Set();
}
private void StartProgressIfNeededThread()
{
int result = WaitHandle.WaitAny(new WaitHandle[] { _finishLoadingNotifier }, ShowProgressTimeOut);
if (result > 1)
{
}
}
source
share