Alex Paluzzi

Alex Paluzzi

  • NA
  • 3
  • 1.9k

Why is MapDrive looping in Try-Catch?...

Nov 3 2010 12:15 PM
Hey guys,

I am using a simple try--catch in C#. When everything is well, the drive maps and moves on. When there is an error and it goes to catch, I get an infinite loop of MessageBox with the error and it seems to be looping the try.


          private void timer5_Tick(object sender, EventArgs e)
        {
            NetworkDrive oNetDrive1 = new NetworkDrive();
            zUpdateStatus("Mapping ********... ");
            try
            {
                oNetDrive1.LocalDrive = "w:";
                oNetDrive1.ShareName = @"\\*******\**";

                //match call to options provided
                if (txtPassword.Text == "" && txtUsername.Text == "")
                {
                    oNetDrive1.MapDrive();
                }
                else if (txtUsername.Text == "")
                {
                    oNetDrive1.MapDrive(txtPassword.Text);
                }
                else
                {
                    oNetDrive1.MapDrive("w2k\\" + txtUsername.Text, txtPassword.Text);
                }
                //update status
                zUpdateStatus("Drive map successful.");

            }
            catch (Exception err1)
            {
                //report error
                zUpdateStatus("Cannot map drive! - " + err1.Message);
                MessageBox.Show(this, "Error (W). The systems administrator has been notified.\nError: " + err1.Message);

            }      

            oNetDrive1 = null;

        }




Thanks...

Answers (2)