关于上一篇,由于有了基本函数,也有了大神给的几乎直接可以用的源码,视乎问题就解决了。
但是问题远远没有那么简单,在测试x64时候出现了比较棘手的问题。
前文我们用到一些有价值的系统函数
在Win32 上我们用 微软的例子用到WaitForSingleObject(hChange, INFINITE)
我们在C# 。.net4.0平台用一个回调函数来完成
_changeHandle = FindFirstPrinterChangeNotification(_printerHandle,
(int) PRINTER_CHANGES.PRINTER_CHANGE_ADD_JOB, 0,
_notifyOptions);
//_mrEvent.Handle = _changeHandle;
_mrEvent.SafeWaitHandle = new SafeWaitHandle(_changeHandle, false);
//use the waitOne
//like C++ smaple if (WaitForSingleObject(hChange, INFINITE) != 0x00000000L) {
//new Thread(PirnterWaitOne).Start();
//Register for the ThreadPool Use callBack
_waitHandle = ThreadPool.RegisterWaitForSingleObject(_mrEvent, new WaitOrTimerCallback(PrinterNotifyWaitCallback), _mrEvent, -1, true);
FindFirstPrinterChangeNotification触发事件的时候,回调我们的函数:
当那么回调函数呢
private void PrinterNotifyWaitCallback(Object state, bool timedOut)
{
try
{
if (_printerHandle != IntPtr.Zero)
{
#region read notification details
_notifyOptions.Count = 1;
int pdwChange;
IntPtr pNotifyInfo;
var bResult = FindNextPrinterChangeNotification(_changeHandle, out pdwChange, _notifyOptions, out pNotifyInfo);