Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果某些方法需要很多时间,我应该将其实现为异步吗?
或者也许在另一个中使用同步Thread(例如使用BackgroundWorker)?
Thread
BackgroundWorker
当您有应该在后台处理的工作项并且您关心它们何时完成时,使用异步调用
如果您有一个在后台运行且需要与 UI 交互的任务,请使用 BackgroundWorker。如果您不在乎他们何时完成任务,请使用它。将数据和方法调用编组到 UI 线程的任务通过其基于事件的模型自动处理。
如果 (1) 您的程序集尚未引用 System.Windows.Form 程序集,(2) 您需要线程成为前台线程,或者 (3) 您需要操纵线程优先级,请避免使用 BackgroundWorker。