我有一个 Winforms 应用程序,我正在尝试打印一个包含多个图层的 pdf 文档。但问题是,这所有操作都在 UI 线程上运行,并且长时间挂起 UI(无响应)。我知道,发生这种情况是因为 UI 线程被阻塞,所以我尝试借助强大的async/await关键字使此操作异步,但我的长时间运行方法仍然不是异步的。它没有从任务中发出await,并且操作仍然与同步操作一样花费相同的时间。
我尝试过的:
请看下面:
/// <summary>
/// Show Print Dialog
/// </summary>
private void ShowPrintDialog()
{
// Initialize print dialog
System.Windows.Controls.PrintDialog prtDialog = new System.Windows.Controls.PrintDialog();
prtDialog.PageRangeSelection = PageRangeSelection.AllPages;
prtDialog.UserPageRangeEnabled = false;
_printOptions.PrintQueue = null;
_printOptions.PrintTicket = null;
Enabled = false;
// if there is a default printer then set it
string defaulPrinter = prtDialog.PrintQueue == null ? string.Empty : prtDialog.PrintQueue.FullName;
// Display the dialog. This returns true if …Run Code Online (Sandbox Code Playgroud) c# multithreading asynchronous task-parallel-library async-await