troubleshooting Question

How can I stop application where I specify

Avatar of IzzyTwinkly
IzzyTwinklyFlag for United States of America asked on
C#
3 Comments1 Solution184 ViewsLast Modified:
Hi
I want to stop my application where I want to.  Please look at the following code:
 private void button1_Click(object sender, EventArgs e)
        {
            string errorMessage = "";
            string aFieldDirectoryPath = @"C:\Hello";
            string bFieldDirectoryPath = @"C:\";
            try
            {
                methodA(aFieldDirectoryPath);
            }
            catch (DirectoryNotFoundException)
            {
                errorMessage += "error in A";
            }
            catch(Exception ex)
            {
                ex.Message.ToString();
                errorMessage += "error in A with something else";
            }

            try
            {
                methodB(bFieldDirectoryPath);
            }
            catch (DirectoryNotFoundException)
            {
                errorMessage += "error in B";
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
                errorMessage += "error in B with something else";
            }

            if (errorMessage.Length > 0)
            {
                canProceed = false;
                MessageBox.Show(errorMessage);
                // Stop HERE!!!!!
            }
        }
I used a flag to track if any exction is occurred.  If there is any errorMessage, the flag becomes false.  If the falg is false, I want my application to be stopped where I marked "Step HERE!!!!" as above.

I don't want to close my application.  I want it to stop running. so System.Environment.Exit(0) wouldn't work here.  Please help!
Thanks~
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros