State Change Problem and

Aug 12, 2012 at 6:17 AM

Hi Agian. 

I Use DialAsync() but my State Change function only write one OpenPort on output screen  (even when the  it is connected  )and my Connection Complete function do nothing because  DialCompletedEvent don't rise.

Any one have any Idea about my problem ?

This is my code.

        private void Dialing()
        {

            Assembly ass = Assembly.GetExecutingAssembly();
            string tempPath = ass.Location + "\\..\\" + "\\Resources\\GPS.pbk";
            this.StatusTextBox.Clear();
            this.Dialer.EntryName = "GPS";
            string path = tempPath;
            this.Dialer.PhoneBookPath = path;
            try
            {
               
                this.Dialer.Credentials = new NetworkCredential("", "");
                               controlTimer.Stop();
                this.handle = this.Dialer.DialAsync();
                //this.handle = this.Dialer.Dial();


            }
            catch (Exception ex)
            {
                this.StatusTextBox.AppendText(ex.ToString());
            }
        }
        private void Dialer_StateChanged(object sender, StateChangedEventArgs e)
        {
            MessageBox.Show("I AM HERE");
            progressBar1.Value = Math.Max(progressBar1.Value + 2, 30);
            this.StatusTextBox.AppendText(e.State.ToString() + "\r\n");
        }

        private void Dialer_DialCompleted(object sender, DialCompletedEventArgs e)
        {
            MessageBox.Show("I AM HERE");
            if (e.Cancelled)
            {
                this.StatusTextBox.AppendText("Cancelled!");
            }
            else if (e.TimedOut)
            {
                this.StatusTextBox.AppendText("Connection attempt timed out!");
            }
            else if (e.Error != null)
            {
                this.StatusTextBox.AppendText(e.Error.ToString());
            }
            else if (e.Connected)
            {
                this.StatusTextBox.AppendText("Connection successful!");
                InitializeNetworkInterface();
                InitializeTimer();
                this.DisconnectButton.Enabled = true;
                DialButton.Enabled = false;
                progressBar1.Value = 30;
                controlTimer.Start();
            }

            if (!e.Connected)
            {
                this.DisconnectButton.Enabled = false;
            }
        }

Coordinator
Aug 12, 2012 at 6:25 PM

Well, I can think of a couple problems you might be having:

  1. You didn't set the SynchronizingObject property on the RasDialer instance and you're trying to update the user interface from a background thread which is causing an exception to be thrown, and you're not handling the Error event to capture this information.
  2. You aren't checking whether there's a problem during dialing on the StateChanged event using the ErrorCode property.

With this component being multi-threaded and hooked into Windows, it has to be careful allowing exceptions to bubble up from the background thread. As far as why your DialCompleted event isn't being raised, I can only suggest you make sure that you're hooking to the event correctly.