ConnMgrEstablishConnectionSync经常因';等待连接';

本文关键字:连接 等待 常因 ConnMgrEstablishConnectionSync | 更新日期: 2023-09-27 18:26:38

我们有一个在WM 6.5上运行的解决方案,该解决方案连接到我们的服务器,但我们的一个客户经常出现问题,我们的软件失去了gprs连接,在重新启动手机之前无法获得新的连接。

我们知道手机位于gprs区域,因为我们可以将桌面远程连接到手机中,并使用internet explorer进行浏览。我们的日志显示,尽管我们指定了2分钟的超时,但ConnMgrEstablishConnectionSync返回的状态为waitingForConnection。有人知道可能出了什么问题吗?有可能某些第三方软件正在窃取我们的连接吗?

非常感谢。

private void Connect()
    {
        if (_connectionHandle != IntPtr.Zero)
        {
            EventLog.AddLogEntry(LogSeverity.Trace, "connmgr - current handle was:" + _connectionHandle);
            CloseConnection();
        }
        const int connectionTimeout = 120000;
        const int CONNMGR_PARAM_GUIDDESTNET = 1;
        const int CONNMGR_PRIORITY_USERINTERACTIVE = 0x8000;
        const int CONNMGR_FLAG_SUSPEND_AWARE = 0x10; // suspended connections supported
        const int CONNMGR_FLAG_NO_ERROR_MSGS = 0x40; // don't show any error messages for failed connections
        const int CONNMGR_proxies = 0x3;
        const string testUrl = "http://www.bbc.co.uk";
        ConnectionInfo info = new ConnectionInfo();
        info.cbSize = (uint)Marshal.SizeOf(info);
        info.bExclusive = 0;
        info.dwFlags = CONNMGR_proxies | CONNMGR_FLAG_NO_ERROR_MSGS | CONNMGR_FLAG_SUSPEND_AWARE;
        info.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE;
        Guid networkGuid = Guid.Empty;
        int hResult = MobileNativeMethods.ConnMgrMapURL(testUrl, ref networkGuid, IntPtr.Zero);
        if (hResult != 0)
        {
            EventLog.AddLogEntry(LogSeverity.Trace, "<<Dllimport - ConnMgrMapURL (error) " + hResult.ToString());
            throw new ConnectionUnavailableException("Unable to open connection");
        }
        info.guidDestNet = networkGuid;
        info.dwParams = CONNMGR_PARAM_GUIDDESTNET;
        uint status = 0;
        hResult = MobileNativeMethods.ConnMgrEstablishConnectionSync(ref info, out _connectionHandle, (uint)connectionTimeout, out status);
        if (hResult != 0)
        {
            EventLog.AddLogEntry(LogSeverity.Trace, "<<Dllimport - ConnMgrEstablishConnectionSync (error) " + networkGuid.ToString());
            throw new ConnectionUnavailableException("Unable to open connection: " + (ConnectionStatus) status);
        }
        EventLog.AddLogEntry(LogSeverity.Trace, "<<Dllimport - ConnMgrMapURL Connection OK");
    }

ConnMgrEstablishConnectionSync经常因';等待连接';

最后,我发现将注册表中的AlwaysOn设置设置为false解决了这个问题。我怀疑霍尼韦尔设备和这种设置存在更深层次的问题,因为摩托罗拉设备似乎可以正常工作,无论其价值如何。