F
Francesco2017
Guest
Hi all,
I have been using the code below (got from searching online) to print my document, without opening the application.
The code work well, unless the printer is offline.
When the printer is offline the application stops with an exception and crashes.
I would like to add some code to prevent crashing of the app.
I have checked many sites for a solution, but it got very complicated for me.
I do not need to know the status of the printer. (although that would be nice)
I need to know how to catch the exception and exit safely.
Can you help please?
Regards
Francesco c
private void Print_RTF_File(string RTF_filepath)
{
//If (printerIsOnline)
//do the printing
//else , error message, exit function
ProcessStartInfo value = new ProcessStartInfo("wordpad.exe");
value.FileName=RTF_filepath;
value.Verb="print";
value.CreateNoWindow=true;
value.WindowStyle=ProcessWindowStyle.Hidden;
Process p = new Process();
p.StartInfo=value;
p.Start();
p.WaitForInputIdle();
System.Threading.Thread.Sleep(4000);
if(false==p.CloseMainWindow())
p.Kill();
}
Continue reading...
I have been using the code below (got from searching online) to print my document, without opening the application.
The code work well, unless the printer is offline.
When the printer is offline the application stops with an exception and crashes.
I would like to add some code to prevent crashing of the app.
I have checked many sites for a solution, but it got very complicated for me.
I do not need to know the status of the printer. (although that would be nice)
I need to know how to catch the exception and exit safely.
Can you help please?
Regards
Francesco c
private void Print_RTF_File(string RTF_filepath)
{
//If (printerIsOnline)
//do the printing
//else , error message, exit function
ProcessStartInfo value = new ProcessStartInfo("wordpad.exe");
value.FileName=RTF_filepath;
value.Verb="print";
value.CreateNoWindow=true;
value.WindowStyle=ProcessWindowStyle.Hidden;
Process p = new Process();
p.StartInfo=value;
p.Start();
p.WaitForInputIdle();
System.Threading.Thread.Sleep(4000);
if(false==p.CloseMainWindow())
p.Kill();
}
Continue reading...