How to use Thread.Sleep in WPF application?
Solution to my problem thanks all for pointing me out in the right direction.
try
{
printer = new Printer();
printer.PrintTicket(dataAdv);
System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 5);
dispatcherTimer.Start();
}
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
if (monitorPrinter.IsPrinterReady() == false)
{
MessageBox.Show("SOME PROBLEM WHEN PRINTING!");
}
}
GibboK
A professional and enthusiastic Senior Front End Developer. Listed as top 2 users by reputation in Czech Republic on Stack Overflow. Latest open source projects Animatelo - Porting to JavaScript Web Animations API of Animate.css (430+ stars on GitHub) Industrial UI - Simple, modular UI Components for Shop Floor Applications Frontend Boilerplate - An opinionated boilerplate which helps you build fast, robust, and adaptable single-page application in React Keyframes Tool - Command line tool which convert CSS Animations to JavaScript objects gibbok.coding📧gmail.com
Updated on June 04, 2022Comments
-
GibboK almost 2 years
In a WPF application VS 2010, I basically need to print a document and check for errors after few seconds it start to print.
At the moment I am using
Thread.Sleep(2000)
but it does not work. Thetry
code I believe is running in the UI thread.Any idea how to fix it? Or better approach?
In this specific case I do not care if the UI Thread is blocked for few seconds.
try { printer = new Printer(); printer.PrintTicket(dataAdv); // check eventual problem during printing like paper jamp Thread.Sleep(2000); if (monitorPrinter.IsPrinterReady() == false) { isPrinterReady = false; MessageBox.Show("Problem during the printing!!!"); } }