In my project method PrintToPrint for crystal report works fine but after installation of the software when Printer is not connected to machine this method makes my software process hangs. Can any one help me solve this issue?
Asked
Active
Viewed 682 times
1 Answers
1
My solution would be to write a function to confirm that the printer is online before making the call to open a crystal report.
using System.Management;
public bool IsPrinterReady(string printerName)
{
bool bprinterOnline = false;
ManagementScope scope = new ManagementScope(@"\root\cimv2");
scope.Connect();
// Select Printers from WMI Object Collections
ManagementObjectSearcher printerSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_Printer");
foreach (ManagementObject printer in printerSearcher.Get())
{
if (string.IsNullOrEmpty(printer["Name"].ToString()))
{
if (printer["Name"].ToString().ToLower().Equals(printerName.ToLower()))
{
switch (printer["WorkOffline"].ToString().ToLower())
{
case "true":
bprinterOnline= true;
break;
case "false":
bprinterOnline= false;
break;
default:
bprinterOnline= false;
break;
}
break;
}
}
}
return bprinterOnline;
}

Gary Kindel
- 17,071
- 7
- 49
- 66
-
Thanks for Help...Gary Kindel – Tulsi Oct 04 '12 at 11:06