0

I need to catch an event when the user launches a print job on a specific printqueue and I don't find any event in System.printing namespace that looks useful to it. I already had a look on these topics :

I also tried this piece of code :

public static void WritePrinterJobs()
    {
        while (true)
        {
            foreach (var job in LocalPrintServer.GetDefaultPrintQueue().GetPrintJobInfoCollection())
            {
                Console.WriteLine(job.Submitter + " " + job.TimeJobSubmitted.ToShortDateString());
            }
            Thread.Sleep(100);
        }
    }

Even if this code work, don't think a while(true) loop is very memory-friendly, especially in my case, because i need to constantly listen to print jobs event.

I also checked the FindFirstPrinterChangeNotification : https://learn.microsoft.com/fr-fr/windows/win32/printdocs/findfirstprinterchangenotification?redirectedfrom=MSDN

But it seems to be a C++ function and I haven't figured out how to make it work in C#.

If someone would help me it would be awesome!

If you need any precisions, just ask !

Cgallien
  • 71
  • 1
  • 4
  • Are you printing from browser? – Always_a_learner Jul 02 '20 at 08:18
  • 1
    https://stackoverflow.com/questions/4276269/printing-event-on-c-sharp. – Always_a_learner Jul 02 '20 at 08:23
  • Thanks for the link, didn't see this one ! The **FindFirstPrinterChangeNotification**, **FindNextPrinterChangeNotification**, and **FindClosePrinterChangeNotification** come back on almost every topic, so it must be a solution, but i'm not sure how to use it in c# because i c++ right ? @Always_a_learner – Cgallien Jul 02 '20 at 08:54
  • 1
    https://social.msdn.microsoft.com/Forums/vstudio/en-US/a7160b44-0984-48c4-afef-b9a6ee4a8483/monitoring-printer-spool-and-copy-file?forum=csharpgeneral – Always_a_learner Jul 02 '20 at 09:03

0 Answers0