0

I am using a third party software for control proxy in my system.
so every network connection uses that proxy software.
in my windows application i have some codes for upload my files through FTP.
i have many try-catch around ftp class and in main application for prevent showing any error and stop the application.
when that proxy software is run and that ftp class is trying to connect to my server and suddenly i close that proxy software my program is closed for unknown reason.
how can i prevet that program to close on crash and keep it alive?
why those tr-catch can not do their job?

EDIT 1 :
those catch parts never run to get the error.
please see this pic :

IMAGE 1

IMAGE 2

but normal exception window is like this :

IMAGE 3

EDIT 2 :
and my try/catch is like below:

class My_FTP
{
    public void upload()
    {
      try
      {
        //Codes

        CRASH IS HERE AND WE NEVER JUMP TO CATCH EREA!!!!!!!!!!!!!!!!!!!!

        while (bytesSent != 0)
       {

       }
      }
      catch (Exception ex)
      {
        Console.WriteLine(ex.ToString());
      }
    }
}


private void Form1_Load(object sender, EventArgs e)
{
  try
  {
    My_FTP my_ftp_ = new My_FTP();
    my_ftp_.upload();
  }
  catch (Exception ex)
  {
    Console.WriteLine(ex.ToString());
  }

  try
  {
    //Other_Codes;
  }
  catch (Exception ex)
  {
    Console.WriteLine(ex.ToString());
  }

}    

i tried these :

Thread: "vshost32-clr2.exe has stopped working" -> not programmatically

VShost32.exe stopped working, but I can continue debugging -> no help

Community
  • 1
  • 1
SilverLight
  • 19,668
  • 65
  • 192
  • 300
  • Where's the try catch code? And what exception are you getting (if you're catching exceptions you should be logging them or doing SOMETHING with them) – Dan Jan 16 '14 at 11:14
  • @your edit: so is that the issue you are having now/did you resolve that issue? – Dan Jan 16 '14 at 11:18
  • ....I asked 2 questions there – Dan Jan 16 '14 at 11:21

3 Answers3

1

Perhaps you should add some kind of logging for when you catch an exception. The reason you program is closing is because when the exception is thrown, the method is being exited, causing your Main method to exit.

Dan
  • 10,282
  • 2
  • 37
  • 64
1

In your try catch block try putting some logic within the catch for example:

catch(Exception e)
{
   MessageBox.Show("Error: " + e.Message, "Exception Thrown", MessageBoxButtons.OK, MessageBoxIcon.Error);
   OtherMethod(); //Or something like this
}

Obviously there will be better ways to go about this, I am only providing a simple solution.

JBurnham
  • 67
  • 9
  • @MoonLight Have you tried putting anything into the catch regardless? – JBurnham Jan 16 '14 at 12:08
  • yes, please see those pictures. those catch parts never run to get the error and this is why i asked the question. – SilverLight Jan 16 '14 at 12:14
  • @MoonLight Does this help at all? http://forums.arcgis.com/threads/41861-quot-vshost32-clr2.exe-has-stopped-working-quot – JBurnham Jan 16 '14 at 12:20
  • yes, that is exactly what i want to tell you. but give me a solution programmatically. i can not tell people to change their control panel because of my program.... – SilverLight Jan 16 '14 at 12:29
  • @MoonLight True, true.. try this: Make sure all of your projects are using the same Framework version ( preferrably 4.0 ) as VS 2010 doesnt like mixed mode framework debugging in X64 bit mode. and also try this: Under your Projects Properties go to Debug tab and Enable Unmanaged Code Debugging. – JBurnham Jan 16 '14 at 12:33
  • hmmmmmm, i have many projects in my solution(both .net 3.5 & 4). but this one is .net 3.5 because my people have .net 3.5 in their computers. so switch to .net 4.0 is little bit difficult. – SilverLight Jan 16 '14 at 12:36
  • might be worth attempting it and seeing if it works? and if it does, try to come up with a work around? – JBurnham Jan 16 '14 at 12:40
1

it may be because of native code in third party library and you cannot catch native Exception in this way, i have faced similar problem when using LibVlc in C#,

you may find some help here to catch native exception (http://msdn.microsoft.com/en-us/magazine/dd419661.aspx)

similar problem Can you catch a native exception in C# code?

also try to remove (Exception ex) from catch statement

Community
  • 1
  • 1
Mujahid Daud Khan
  • 1,983
  • 1
  • 14
  • 23