开发者

Progress reporting to parent UI thread

开发者 https://www.devze.com 2023-02-19 01:43 出处:网络
apologies if I don\'t explain this clearly, but I\'m writing an app which is causing me some problems with threading.

apologies if I don't explain this clearly, but I'm writing an app which is causing me some problems with threading.

I have a UI which starts a System.Timers.Timer. Each time this timer elapses it trigge开发者_JS百科rs a workflow which opens a progress screen. To prevent another workflow starting before the last one has finished it locks an object on the main form. This progress screen starts and reports the progress of, some file copying using FileCopyEX.

The problem I'm having is that the progress screen does not display until after the work flow has been completed.

Hopefully this will make it clearer:

Main Form | Timer Elapses | WorkFlow Starts | Progress Screen opens (errors which occur go back to the previous) | File copying occurs (progress reported back to progress screen) If no errors, returns to main screen before next tick.

Until now I've only implemented very simple threading, so I'm not sure how best to implement this. I've tried starting the workflow on a BackGroundWorker to seperate it from the UI thread but it behaves the same.

Thanks


I suggest that you read about the BackgroundWorker. This has hooks for reporting progress.

Remember that system timers invoke its event handler on a non-UI thread. Whenever, you do something with the UI you must be on the UI thread.


Without the code I can only guess at the cause, but the likely reason is that the Progress window needs the UI to be pumping messages to appear - i.e. the UI thread needs to be running.

If the UI thread is busy running your workflow, then it won't get around to processing the displaying of your window until after that. You need to separate your flow so that the progress window is on your UI thread and the workflow is on a background thread.

Hope that makes sense!

0

精彩评论

暂无评论...
验证码 换一张
取 消