c# with dotras - 拨号后状态框不会自动更新 connect/disconnect
c# with dotras - Status Box not updating automatically after dial connect/disconnect
问候,
- OS: Windows 7 /64位
- 应用程序:Visual Studio 2012 / C# 和 DotRas 1.3 库
我对 C# 或 VS 非常陌生,所以请多多包涵。经过数小时的研发,我终于用 C# / Dotras 制作了一个 pppoe 拨号器程序。这个程序有 3 个主要按钮
- 在网络连接中创建/添加 PPPoE Internet 拨号器连接,工作正常
- 拨号按钮,连接新建的拨号器,正常工作
- 断开连接工作正常
我添加了 StatuBox,拨号事件应该出现在 dotras youtube 视频教程中(用于 vpn,但我的项目用于 pppoe 拨号器)
StatusBox 没有更新像connecting/password error/connected 等拨号事件。这是我最终感到困惑的部分。
以下是我的代码。
// Dial Button Action
private void button2_Click_1(object sender, EventArgs e)
{
using (RasDialer dialer = new RasDialer())
{
// I had to add below line to update statusTextBox Manualy , want to get rid of it by adding auto status update
this.StatusTextBox.AppendText(string.Format("{0}\r\n\r\n", "Connection in progress ...", "{0}\r\n\r\n"));
dialer.EntryName = ("pppoe2");
string username = textBox1.Text;
string passwd = textBox2.Text;
// If username is empty dont connect
if (string.IsNullOrWhiteSpace(textBox1.Text))
{
this.StatusTextBox.AppendText(string.Format("{0}\r\n", "Cancelled. Cannot continue with username/password.", "{0}\r\n"));
MessageBox.Show("Enter username.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
dialer.Credentials = new System.Net.NetworkCredential(textBox1.Text, textBox2.Text);
dialer.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.User);
dialer.Timeout = 1000;
dialer.AllowUseStoredCredentials = true;
// start dialing,
dialer.Dial();
// If dialer connects successfully update StatuTextbox
this.StatusTextBox.AppendText(string.Format("{0}\r\n\r\n", "Connected."));
}
}
private void rasDialer1_StateChanged(object sender, StateChangedEventArgs e)
{
this.StatusTextBox.AppendText(string.Format("{0}\r\n", "Status Changed"));
}
private void rasDialer1_Error(object sender, System.IO.ErrorEventArgs e)
{
this.StatusTextBox.AppendText(string.Format("{0}\r\n", "STATUS UPDATE TEXT XYZ"));
}
private void rasDialer1_DialCompleted(object sender, DialCompletedEventArgs e)
{
this.StatusTextBox.AppendText(string.Format("{0}\r\n", "STATUS UPDATE TEXT XYZ"));
}
如有任何帮助,我们将不胜感激。
好的,我成功地启用了状态框文本附加功能。
this.Invoke((MethodInvoker)delegate
{
this.StatusTextBox.AppendText(string.Format(e.State.ToString() + "\r\n"));
});
}
根据您的使用方式,如果来自 OS 的后台线程未编组回 UI 线程,则它不会更新。与您所做的类似,RasDialer 上的 SynchronizingObject 属性 可以设置为您的表单,线程同步将自动发生。
问候,
- OS: Windows 7 /64位
- 应用程序:Visual Studio 2012 / C# 和 DotRas 1.3 库
我对 C# 或 VS 非常陌生,所以请多多包涵。经过数小时的研发,我终于用 C# / Dotras 制作了一个 pppoe 拨号器程序。这个程序有 3 个主要按钮
- 在网络连接中创建/添加 PPPoE Internet 拨号器连接,工作正常
- 拨号按钮,连接新建的拨号器,正常工作
- 断开连接工作正常
我添加了 StatuBox,拨号事件应该出现在 dotras youtube 视频教程中(用于 vpn,但我的项目用于 pppoe 拨号器)
StatusBox 没有更新像connecting/password error/connected 等拨号事件。这是我最终感到困惑的部分。
以下是我的代码。
// Dial Button Action
private void button2_Click_1(object sender, EventArgs e)
{
using (RasDialer dialer = new RasDialer())
{
// I had to add below line to update statusTextBox Manualy , want to get rid of it by adding auto status update
this.StatusTextBox.AppendText(string.Format("{0}\r\n\r\n", "Connection in progress ...", "{0}\r\n\r\n"));
dialer.EntryName = ("pppoe2");
string username = textBox1.Text;
string passwd = textBox2.Text;
// If username is empty dont connect
if (string.IsNullOrWhiteSpace(textBox1.Text))
{
this.StatusTextBox.AppendText(string.Format("{0}\r\n", "Cancelled. Cannot continue with username/password.", "{0}\r\n"));
MessageBox.Show("Enter username.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
dialer.Credentials = new System.Net.NetworkCredential(textBox1.Text, textBox2.Text);
dialer.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.User);
dialer.Timeout = 1000;
dialer.AllowUseStoredCredentials = true;
// start dialing,
dialer.Dial();
// If dialer connects successfully update StatuTextbox
this.StatusTextBox.AppendText(string.Format("{0}\r\n\r\n", "Connected."));
}
}
private void rasDialer1_StateChanged(object sender, StateChangedEventArgs e)
{
this.StatusTextBox.AppendText(string.Format("{0}\r\n", "Status Changed"));
}
private void rasDialer1_Error(object sender, System.IO.ErrorEventArgs e)
{
this.StatusTextBox.AppendText(string.Format("{0}\r\n", "STATUS UPDATE TEXT XYZ"));
}
private void rasDialer1_DialCompleted(object sender, DialCompletedEventArgs e)
{
this.StatusTextBox.AppendText(string.Format("{0}\r\n", "STATUS UPDATE TEXT XYZ"));
}
如有任何帮助,我们将不胜感激。
好的,我成功地启用了状态框文本附加功能。
this.Invoke((MethodInvoker)delegate
{
this.StatusTextBox.AppendText(string.Format(e.State.ToString() + "\r\n"));
});
}
根据您的使用方式,如果来自 OS 的后台线程未编组回 UI 线程,则它不会更新。与您所做的类似,RasDialer 上的 SynchronizingObject 属性 可以设置为您的表单,线程同步将自动发生。