有人可以給我一個擡頭...我試圖使用dotRAS .NET控件,並且此代碼使用事件處理程序更改internetConnected
(布爾值)的值...dotRAS斷開狀態未觸發
但似乎狀態RasConnectionState.Disconnected
沒有被dotRAS掛斷()觸發..
任何想法?我是否完全錯了......或者我是否設法找到了錯誤?
public class USBModem
{
// private vars
private RasDialer dialer = new RasDialer();
private bool internetConnected = false;
/// <summary>
/// Default constructor for USBModem
/// </summary>
public USBModem()
{
// Add Events for dialer
dialer.StateChanged += new EventHandler<StateChangedEventArgs>(dialer_StateChanged);
}
void dialer_StateChanged(object sender, StateChangedEventArgs e)
{
// Handle state changes here
switch (e.State)
{
case RasConnectionState.Connected:
internetConnected = true;
Console.WriteLine(e.State.ToString());
break;
case RasConnectionState.Disconnected:
internetConnected = false;
Console.WriteLine(e.State.ToString());
break;
default:
Console.WriteLine("INFO -> Unhandled state: " + e.State.ToString());
break;
}
}
public void ConnectInternet(string connectionName)
{
// Dial
dialer.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers);
dialer.EntryName = connectionName;
dialer.DialAsync();
}
public void DisconnectInternet()
{
foreach (RasConnection connection in dialer.GetActiveConnections())
{
connection.HangUp();
}
}
}
謝謝傑夫。我會更新源:) – Darbio 2010-09-10 13:49:12
嘿@ jeff-winn,這是一個偉大的圖書館,謝謝。 – Ads 2016-11-02 02:24:26