How to catch print jobs in C# .NET

.net, c#, printing

Solution

I found the solution. For those are searching for a way to handle print job events take a look:

FindFirstPrinterChangeNotification

and also a working code can be found Monitoring print jobs

Problem

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.

Original source