Search code examples
c#visual-studio-2012dotras

c# with dotras - Status Box not updating automatically after dial connect/disconnect


Greeting,

  • OS: Windows 7 /64bit
  • Application: Visual Studio 2012 / C# and DotRas 1.3 Library

I am very new to c# or VS thing so please bear with me. After doing many hours R&D, I have finaly made a pppoe dialer program in C# / Dotras. This program have 3 main buttons

  1. Create /Add PPPoE Internet Dialer Connection in network connections , working fine
  2. Dial button, which connects the newly created dialer , working Fine
  3. Disconnect working fine

I have added StatuBox where dialup events should appear as showed on dotras youtube video tutorial (which was for vpn, but my project is for pppoe dialer)

StatusBox Not updating the dialup events like connecting/password error/connected etc. This is the part where I am finally confused.

Following is my Code.

// 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"));
}

Any help would be highly appreciable.


Solution

  • Ok I have managed to enable status box text append work fine.

    this.Invoke((MethodInvoker)delegate
    {
    this.StatusTextBox.AppendText(string.Format(e.State.ToString() + "\r\n"));
    });
    }