![](/img/trans.png)
[英]Using 2 Dispatcher Timer at different times in Windows Store Application with C#
[英]Dispatcher is not coming on C# Windows Forms Application
我有一個帶有進度條的C#Windows窗體應用程序。 我想根據某些方法狀態動態地進行。 我在一個單獨的類中有該方法,並為該方法創建一個新線程,並使用委托將該方法的狀態傳遞給父線程。
我可以使用progressbar.Dispatcher
在WPF應用程序中解決相同的情況但在Windows窗體應用程序中沒有Dispatcher,即使我使用System.Threading
命名空間也是如此。
progressbar.Dispatcher
似乎只在WPF應用程序中可用。
在winforms中,您可以使用ProgressBar.Invoke或ProgressBar.BeginInvoke從另一個線程更新控件。
在Windows窗體應用程序中, BackgroundWorker
應完全適合您的任務。 特別是,它具有ReportProgress
方法,用於根據您的計算發送進度,而ProgressChanged
用於跟蹤UI線程的更改。 有關完整詳細信息,請參閱MSDN文章
在WinForms中, Invoke/BeginInvoke
方法直接在控件對象上,您可以從System.Windows.Forms.Control的文檔中看到。 所以你有progressBar.BeginInvoke(...)
例如。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.