// Called on an arbitrary thread. int NativeMethods.IQueryCancelAutoPlay.AllowAutoPlay(String pszPath, UInt32 dwContentType, String pszLabel, UInt32 dwSerialNumber) { int hr = NativeMethods.S_OK; // Is it the drive we want to cancel Autoplay for? if (pszPath.IndexOfAny(CancelAutoPlayDriveList.ToCharArray()) != -1) { // Notify anyone who cares. lock (_TheLock) { if (_CancelAutoPlay != null) { // String msg = String.Format("Rejected AutoPlay for drive {0}", pszPath); CancelAutoPlayEventArgs args = new CancelAutoPlayEventArgs(pszPath, pszLabel, "VolumeArrival", dwSerialNumber); // Post the message to the UI Thread. _SynchronizationContext.Post(new SendOrPostCallback(_CancelAutoPlay), args); } } // Setting the return value to S_FALSE cancels the AutoPlay mechanism. hr = NativeMethods.S_FALSE; Trace.WriteLine(String.Format("*** DeviceManager.Instance.IQueryCancelAutoPlay.AllowAutoPlay(): Rejected AutoPlay Drive: {0}, thread({1})", pszPath, Thread.CurrentThread.GetHashCode())); } return(hr); }
// Called on an arbitrary thread. int NativeMethods.IHWEventHandler.HandleEvent(String pszDeviceID, String pszAltDeviceID, String pszEventType) { // Notify anyone who cares. lock (_TheLock) { if (_CancelAutoPlay != null) { // String msg = String.Format("Rejected \"{0}\" AutoPlay event for device: {1}( {2} )", pszEventType, pszAltDeviceID, pszDeviceID); CancelAutoPlayEventArgs args = new CancelAutoPlayEventArgs(pszDeviceID, pszAltDeviceID, pszEventType, 0); // Post the message to the UI Thread. _SynchronizationContext.Post(new SendOrPostCallback(_CancelAutoPlay), args); } } Trace.WriteLine(String.Format("*** DeviceManager.Instance.IHWEventHandler.HandleEvent(): Handled \"{0}\" AutoPlay event for device: {1}( {2} ), thread({3})", pszEventType, pszAltDeviceID, pszDeviceID, Thread.CurrentThread.GetHashCode())); return(NativeMethods.S_OK); }