public MainForm() { InitializeComponent(); try { m_manager = new OpenNETCF.Net.ConnectionManager(); } catch (PlatformNotSupportedException) { } if (m_manager.SupportsStatusNotifications) { m_detailCollection = m_manager.GetConnectionDetailItems(); m_detailCollection.ConnectionDetailItemsChanged += new ConnectionStateChangedHandler(m_detailCollection_ConnectionDetailItemsChanged); } else { // TODO: notify user / maybe spawn a watcher thread? m_manager.ConnectionStateChanged += new ConnectionStateChangedHandler(m_manager_ConnectionStateChanged); } RefreshDestinations(); }
public static void EnsureCellularConnection() { ConnectionManager connectionManager = new ConnectionManager(); ConnectionDetailCollection connections = connectionManager.GetConnectionDetailItems(); ConnectionDetail connection = null; foreach (ConnectionDetail c in connections) { if (c.ConnectionType == ConnectionType.Cellular) { connection = c; break; } } if (connection == null) { UIHelper.DisplayWarning("No cellular network configured"); return; } if (connection.ConnectionStatus != ConnectionStatus.Connected) { try { connectionManager.Connect(connection.DestinatonNetwork, true, ConnectionMode.Synchronous); Thread.Sleep(3000); } catch (Exception ex) { UIHelper.DisplayWarning(ex.Message); } } }