Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2006

Tip: Looking for answers? Try searching our database.

Intercept crash of an external exe

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
lookaround - 23 Nov 2006 16:16 GMT
Hi everyone,
 I need some help...
I call an external exe (a command-line tool) with Process.Start through
this code:

          try
           {
               p = new Process();
               p.StartInfo.UseShellExecute = false;
               p.StartInfo.FileName = ExePath;
               p.StartInfo.Arguments = "";
               p.Start();
               p.PriorityClass = ProcessPriorityClass.BelowNormal;
          }
           catch (Exception exc) //Win32Exception err
           {
               Console.Writeline(exc.Message);
           }

           p.WaitForExit();
           if (p.ExitCode == 0)
           {
               tbLog.Text += "All ok." + Environment.NewLine;
           }
           else
           {
               tbLog.Text += "Exit code: " + p.ExitCode.ToString() +
Environment.NewLine;
           }

If the external exe crashes, it displays a window:
"An error occurred ... application will be closed"
"For further information ... click here" (I translate from Italian).
and the two buttons "Debug" and "Close"

Until I click on Debug or Close the calling application freezes.
After I click on one of the two buttons, the calling app return
responsive and logs the err message (exit code).

The fact that application freezes while executing external exe is not a
problem; the problem is that the app has to be run in un-attended
mode...
So it should intercept the external crash, handle the crash and go on,
not wait for a click by the user.

I should also check if the external exe runs for more than a fixed
number of seconds: if it runs longer, I should have to kill the exe and
handle the unfinished execution (without no external input or click)

Any help?

Thank you very much in advance for any idea!
Chris - 24 Nov 2006 01:52 GMT
If I understand you correctly:
1) You are launching an exe using Process.Start()
2) When the exe you launched crashes, windows puts up a dialog asking if you
want to debug it
3) Until something clicks the dialog, the exe doesn't return, and your
origanal app is waiting
4) You want to know how to clear that dialog automatically

If all that is correct, then this might help:
1) You could spawn a seperate thread and enumerate windows - then send a
click event to the correct button whenever you see the dialog you want
cleared
2) Or, you could just tell windows not to put that dialog up anymore.  Check
out
http://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/regentry/114
99.mspx?mfr=true


I think that will work for you.

-Chris

> Hi everyone,
>  I need some help...
[quoted text clipped - 48 lines]
>
> Thank you very much in advance for any idea!
lookaround - 24 Nov 2006 07:25 GMT
Thank you for tips!

> If I understand you correctly:
> 1) You are launching an exe using Process.Start()
[quoted text clipped - 3 lines]
> origanal app is waiting
> 4) You want to know how to clear that dialog automatically

You understood perfectly.

> If all that is correct, then this might help:
> 1) You could spawn a seperate thread and enumerate windows - then send a
> click event to the correct button whenever you see the dialog you want
> cleared

I'm executing the exe from an asp.net application page.
I'm not so experienced with Thread and capture external windows events
and clicks...
Should you suggest me some tutorial or web page where I can found some
code to start from?
Thanks again in advance..

> 2) Or, you could just tell windows not to put that dialog up anymore.  Check
> out
[quoted text clipped - 56 lines]
> >
> > Thank you very much in advance for any idea!
Chris - 25 Nov 2006 09:47 GMT
I wasn't actually recommending option 1 as a viable choice :}

I recommend you make option 2 work for you if you can; if for some reason
you can't, reply back to me (not the whole group) and I'll help you get your
problem solved.

-Chris

> Thank you for tips!
>
[quoted text clipped - 82 lines]
>> >
>> > Thank you very much in advance for any idea!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.