FindFirstPrinterChangeNotification
およびを使用して、FindNextPrinterChangeNotification
印刷イベントをキャッチしています。FindNextPrinterChangeNotification
ただし、すべてのイベントを確実に返すわけではないことに気付きました。この記事で同じ問題を抱えている人を見つけました。
基本的に、プログラムをデバッグしたり、イベントを処理するときに彼の提案のように Sleep コマンドを入れたりFindNextPrinterChangeNotification
すると、多くのイベントがスキップされます。また、後で処理するためにすでにジョブをキューにプッシュしているにもかかわらず、ほとんどの場合、多くの SPOOLING ステータス イベントを取得しますが、DELETED ステータス イベントを見逃します (取得できる場合もありますが、ほとんどの場合は取得できません)。
誰もこの問題を抱えていますか?また、Microsoft PDF プリンターを試していますNumberOfPages
。SPOOLING イベントが発生すると増加しますが、増加しNumberOfPagesPrinted
ません。それは意図されていますか?
編集いくつかの調査の後、イベントは実際にはなくなっていません。別の印刷ジョブを呼び出すと、以前のイベントが発生します (以前の印刷ジョブの DELETING/DELETED ステータスを含む)。何が問題なのか教えてください。
を呼び出すコードは次のFindFirstPrinterChangeNotification
とおりです。
//We got a valid Printer handle. Let us register for change notification....
_changeHandle = FindFirstPrinterChangeNotification(_printerHandle, (int)PRINTER_CHANGES.PRINTER_CHANGE_JOB, 0, _notifyOptions);
// We have successfully registered for change notification. Let us capture the handle...
_mrEvent.SafeWaitHandle = new Microsoft.Win32.SafeHandles.SafeWaitHandle(_changeHandle, true);
//Now, let us wait for change notification from the printer queue....
_waitHandle = ThreadPool.RegisterWaitForSingleObject(_mrEvent, new WaitOrTimerCallback(PrinterNotifyWaitCallback), _mrEvent, -1, true);
そして、これは次の場合ですFindNextPrinterChangeNotification
。
_notifyOptions.Count = 1;
_notifyOptions.dwFlags = PRINTER_NOTIFY_OPTIONS_REFRESH;
int pdwChange = 0;
IntPtr pNotifyInfo = IntPtr.Zero;
bool bResult = FindNextPrinterChangeNotification(_changeHandle, out pdwChange, _notifyOptions, out pNotifyInfo);