ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 发起GPRS拨号请求

发起GPRS拨号请求

原创 Linux操作系统 作者:freshairpeng 时间:2009-03-04 16:05:36 0 删除 编辑

using System;
using System.Collections.Generic;
using System.Text;
using OpenNETCF.Net;
using System.Windows.Forms;
using Microsoft.Win32;

namespace AnotherTodayScreenItem.Utl
{
    ///


    /// 发起GPRS拨号请求
    ///

    class ConnectNet
    {
        private OpenNETCF.Net.ConnectionManager ConnMgr = new OpenNETCF.Net.ConnectionManager();
        private DestinationInfoCollection cenum;
        private bool is_connected;
        private static volatile ConnectNet m_instance = null;

        public ConnectNet()
        {
        }

        public static ConnectNet singleton
        {
            get
            {
                if (m_instance == null)
                {
                    lock (typeof(ConnectNet))
                    {
                        if (m_instance == null)
                        {
                            m_instance = new ConnectNet();
                        }
                    }
                }

                return m_instance;
            }
        }


        public void ConnGPRS(bool connect)
        {
          
            long startTime;
            cenum = ConnMgr.EnumDestinations();
            List connectionDetail = ConnectionManager.ConnectionDetailItems;
            is_connected = false;
            try
            {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
                foreach (ConnectionDetail em in connectionDetail)
                  {
                    if (em.Description == "linkgprs")
                    {
                        if (connect)
                        {
                            RegMobile regManager = new RegMobile();
                            regManager.changeValue(RegMobile.HKEY.HKEY_LOCAL_MACHINE, em.Description);
                            ConnMgr.Connect(em.DestinatonNetwork, true, ConnectionMode.Asynchronous);
                            //mmmmmmmmmmmmmmmmmmmmmmmmConnMgr.Connect(em.DestinatonNetwork, true, ConnectionMode.Asynchronous);
                            startTime = DateTime.Now.Ticks;
                            while ((!is_connected) && (DateTime.Now.Ticks - startTime < 20 * TimeSpan.TicksPerSecond)) ;
                            break;
                        }
                        else
                        {
                            ConnMgr.RequestDisconnect();
                        }
                    }
                }

            }
            catch (SystemException err)
            {
                MessageBox.Show(" err 700 " + err.Message);
            }
        }

        public void close_connect()
        {
            ConnMgr.RequestDisconnect();
        }
    }
}

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/14766526/viewspace-561396/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-02-25

  • 博文量
    69
  • 访问量
    246675