, , NOTIFICATION_EVENT_RS232_DETECTED. CeRunAppAtEvent ( , , ), "EventActiveSync", .
, , .
, - WaitForSingleObject, , . ,
event EventHandler OnConnect = delegate{};
void ListenerThreadProc()
{
var eventName = "OnConnect";
IntPtr @event = NativeMethods.CreateEvent (IntPtr.Zero, true, false, eventName);
NativeMethods.CeRunAppAtEvent (
string.Format("\\\\.\\Notifications\\NamedEvents\\{0}", eventName),
(int) NOTIFICATION_EVENT.NOTIFICATION_EVENT_RS232_DETECTED);
while(!m_shutdown)
{
if(NativeMethods.WaitForSingleObject(@event, 1000) == 0)
{
OnConnect(this, EventArgs.Empty);
}
}
NativeMethods.CeRunAppAtEvent (
string.Format("\\\\.\\Notifications\\NamedEvents\\{0}", eventName),
(int) NOTIFICATION_EVENT.NOTIFICATION_EVENT_NONE);
NativeMethods.CloseHandle(@event);
}
, OnConnect.
FWIW, SDF , - :
DeviceManagement.SerialDeviceDetected += DeviceConnected;
...
void DeviceConnected()
{
}