Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi. I have a windows form program that updates info when an existing activesync connection is active.

I'd like to write an event handler that will automatically update the form when a new Mobile 6.5 device is cradled.

Does anyone have a complete example of this?

All the code snippets found with Google don't work for me.

Thanks in advance.

Let me extend the question.

What I've done so far is put these lines in the form's CTOR

C#
m_rapi.RAPIConnected += new RAPIConnectedHandler(m_rapi_RAPIConnected);

            m_rapi.RAPIDisconnected += new RAPIConnectedHandler(m_rapi_RAPIDisconnected);

            m_rapi.Connect(false, -1);


Then I have:

C#
private void m_rapi_RAPIConnected()
        {

            MessageBox.Show("Connected");
            Dostuff();

        }



        private void m_rapi_RAPIDisconnected()
        {
            MessageBox.Show("Disconnected");
            clearForm();

        }



When I start the program and the Mobile device is already connected, I get the messagebox but nothing else happens.

I fixed that by changing

m_rapi.Connect(false, -1);


to

m_rapi.Connect(true, -1);


The stuff in dostuff() now executes.

However, when I disconnect the device, the messagebox pops up, but the clearform() does nothing.

Also, when I reconnect the device, the connect method doesn't execute, which I assume is because it's in the CTOR.

Any ideas how to fix both problems?
Posted
Updated 22-Oct-14 13:16pm
v2
Comments
BillWoodruff 22-Oct-14 0:48am    
Is there a physical connection between the mobile device and the Win computer ?
George Jonsson 22-Oct-14 0:52am    
Divide your problem into smaller pieces and then search for a solution for each bit.
In the same fashion you eat an elephant.
Sinisa Hajnal 22-Oct-14 2:19am    
What snippets? Show us what you did before, that way you will not get as solution something you already tried.
Spidy1 22-Oct-14 22:49pm    
Just to clarify, the clearform() method is meant to clear the form on the PC, not the form on the mobile device.
Spidy1 22-Oct-14 23:07pm    
Further comment, I think I have a cross threading problem.

1 solution

I solved the crossthreadmessagingexception by using a delegate.

XML
private void m_rapi_RAPIDisconnected()
         {
             Invoke((new updateFormDelegate(updateForm)));
         }



        
         private delegate void updateFormDelegate();



        
         void updateForm()
         {
             txtIPAddress.Clear();
             ...

         }



So now, I can detect a connection and disconnection when the form first loads.

But after an initial connection the disconnection, when I reconnect, it's not detected.

How can I automatically capture subsequent connections/disconnections?

Any suggestions would be greatly appreciated.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900