I am trying to catch every print jobs submitted to printer in our local network. I want to display some properties of the job like job name, submit time and so on.
I tried a while loop but it didn't catch my print job, maybe beacuse it happened while the thread was sleeping. Is there an event that I can register and handle? I don't want to spend all of the CPU resource for this task infinetly looping.
I tried this:
public static void WritePrinterJobs()
{
while (true)
{
foreach (var job in LocalPrintServer.GetDefaultPrintQueue().GetPrintJobInfoCollection())
{
Console.WriteLine(job.Submitter + " " + job.TimeJobSubmitted.ToShortDateString());
}
Thread.Sleep(100);
}
}
EDIT: The code above actually works, you don't need to go lower level if it does work for you, my mistake was not configuring default printer correctly.