dotRAS 断开状态未触发
有人可以提醒我吗...我正在尝试使用 dotRAS .NET 控件,并且此代码使用事件处理程序更改 internetConnected
(布尔值)的值...
但是它似乎状态 RasConnectionState.Disconnected
不是由 dotRAShangup() 触发的。
有什么想法吗?我做的是完全错误的......还是我设法找到了一个错误?
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();
}
}
}
Can someone give me a heads up... I'm trying to use the dotRAS .NET control, and this code to change the value of internetConnected
(boolean) using an event handler...
But it seems that the state RasConnectionState.Disconnected
is not triggered by dotRAS hangup()..
Any ideas? Am I doing it totally wrong... or have I managed to find a bug?
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();
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在 1.2 版本中对 RasDialer 的文档进行了一些更改,希望能解决这个问题。
I've made some changes to the documentation for RasDialer in the 1.2 release to hopefully address this problem.
显然,这是一个非常简单(但普遍)的错误。
基本上,RasDialer 组件仅在拨号操作正在进行时处理事件。
如果在连接尝试期间调制解调器线路可能被拔出,则会引发断开连接事件。
如果您想监视计算机上的客户端连接以了解连接/断开连接或一些其他事件,请使用
RasConnectionWatcher
。当在拨号操作之外进行连接更改时,这将收到来自 Windows 的通知。Google 上有关 dotRAS 的文档特别稀疏...前往 http://dotras.codeplex.com 了解更多信息信息。 SDK 中包含的帮助文件也非常有用。
Apparently, a very simple (but widespread) mistake.
Basically the
RasDialer
component only handles events while a dialing operation is in progress.The disconnected event would be raised if perhaps the modem line became unplugged during the connection attempt.
If you want to monitor client connections on the machine for connection/disconnection or a couple other events, use a
RasConnectionWatcher
. This will receive notifications from Windows when connection changes are made outside of a dialing operation.Documentation on dotRAS is particularly sparse on Google... Head to http://dotras.codeplex.com for further information. The Help files included with the SDK are also very useful.