WIN CE 5.0 ActiveSync Connect / Disconnect?

I need to cancel the transfer of software from Windows Mobile 6.5 to Windows CE 5.0, which currently detects when the device is in the base unit (ActiveSync is running).

I need to know when ActiveSync is running on a device so that I can prepare the device to send and receive files.

I found an article about using PINVOKE methods like CeRunAppAtEvent, but I don't know how this will work.

    bool terminateDeviceEventThreads = false;
    IntPtr handleActiveSyncEndEvent;

    while (!terminateDeviceEventThreads)
        {
        handleActiveSyncEndEvent = NativeMethods.CreateEvent (IntPtr.Zero,
                                            true, false, "EventActiveSync");
        if (IntPtr.Zero != handleActiveSyncEndEvent)
            {
            if (NativeMethods.CeRunAppAtEvent ("\\\\.\\Notifications\\NamedEvents\\EventActiveSync",
                         (int) NOTIFICATION_EVENT.NOTIFICATION_EVENT_RS232_DETECTED))
                {
                NativeMethods.WaitForSingleObject (handleActiveSyncEndEvent, 0);

                //

                NativeMethods.ResetEvent (handleActiveSyncEndEvent);
                if (!NativeMethods.CeRunAppAtEvent ("\\\\.\\Notifications\\NamedEvents\\EventActiveSync",
                                 (int) NOTIFICATION_EVENT.NOTIFICATION_EVENT_NONE))
                    {
                    break;
                    }
                handleActiveSyncEndEvent = IntPtr.Zero;
                }
            }
        }
+3
source share
2 answers

, , NOTIFICATION_EVENT_RS232_DETECTED. CeRunAppAtEvent ( , , ), "EventActiveSync", .

, , .

, - WaitForSingleObject, , . ,

event EventHandler OnConnect = delegate{};

void ListenerThreadProc()
{
    var eventName = "OnConnect";

    // create an event to wait on
    IntPtr @event = NativeMethods.CreateEvent (IntPtr.Zero, true, false, eventName);

    // register for the notification
    NativeMethods.CeRunAppAtEvent (
           string.Format("\\\\.\\Notifications\\NamedEvents\\{0}", eventName),
           (int) NOTIFICATION_EVENT.NOTIFICATION_EVENT_RS232_DETECTED);

    while(!m_shutdown)
    {
        // wait for the event to be set
        // use a 1s timeout so we don't prevent thread shutdown
        if(NativeMethods.WaitForSingleObject(@event, 1000) == 0)
        {
            // raise an event
            OnConnect(this, EventArgs.Empty);
        }
    }

    // unregister the notification
    NativeMethods.CeRunAppAtEvent (
           string.Format("\\\\.\\Notifications\\NamedEvents\\{0}", eventName),
           (int) NOTIFICATION_EVENT.NOTIFICATION_EVENT_NONE);

    // clean up the event handle
    NativeMethods.CloseHandle(@event);
}

, OnConnect.

FWIW, SDF , - :

DeviceManagement.SerialDeviceDetected += DeviceConnected;
...
void DeviceConnected()
{
    // handle connection
}
+4

ActiveSync MSDN. , . this

CeRunAppAtEvent, Native,

[DllImport("coredll.dll", EntryPoint="CeRunAppAtEvent", SetLastError=true)]  
private static extern bool CeRunAppAtEvent(string pwszAppName, int lWhichEvent);

PInvode MSDN

+1

All Articles