如何编写事件处理程序以自动检测新的activesync连接。 [英] How to write an event handler to automatically detect new activesync connections.

查看:53
本文介绍了如何编写事件处理程序以自动检测新的activesync连接。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我有一个Windows窗体程序,当现有的activesync连接处于活动状态时更新信息。



我想编写一个事件处理程序,当a时会自动更新表单新的Mobile 6.5设备已经支撑。



有没有人有完整的这样的例子?



Google发现的所有代码片段对我都不起作用。



提前致谢。



让我延长这个问题。



到目前为止我所做的是将这些行放在表格的CTOR中



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

m_rapi.RAPIConnected += new RAPIConnectedHandler(m_rapi_RAPIConnected);

            m_rapi.RAPIDisconnected += new RAPIConnectedHandler(m_rapi_RAPIDisconnected);

            m_rapi.Connect(false, -1);





然后我有:





Then I have:

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





to

m_rapi.Connect(true, -1);





dostuff中的东西()现在执行。



然而,当我断开设备时,会弹出消息框,但clearform()什么都不做。



另外,当我重新连接设备时,connect方法不会执行,我认为这是因为它在CTOR中。



任何想法如何解决这两个问题?



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?

推荐答案

我使用委托解决了crossthreadmessagingexception。



I solved the crossthreadmessagingexception by using a delegate.

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.


这篇关于如何编写事件处理程序以自动检测新的activesync连接。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆