|
-
Sep 7th, 2012, 01:29 AM
#1
Catching “unhandled exception” caused by a Process
My code looks something like this:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myProcess As New Process
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
myProcess.StartInfo.CreateNoWindow = True
myProcess.StartInfo.WorkingDirectory = "X:\folder\where\console\program\resides"
myProcess.StartInfo.FileName = "third_party_console_program.exe"
myProcess.StartInfo.Arguments = "some: arguments goes here"
myProcess.Start()
myProcess.WaitForExit()
MsgBox("Done")
End Sub
I am using Process to start a console program. What this console program does is, it would detect whether a particular device is connected via usb, and tries to read some block of data. But the problem is, when no devices are connected, it is giving an unhandled exception(this is thrown by the console_program. Not my WinForm program). When a device is connected, no problem is there !
I think it is probably trying to read from the usb, even when it doesn't detect any device. Since this console app is of a third party program, I couldn't do anything on it.
Instead what I am trying to do is, to catch the unhandled exception and output the message "Couldn't detect the device !"
But the normal Try..Catch block covered on the above piece of code won't work as I think the exception is thrown on a separate thread.
Any ideas on how to catch this ? Any tips or suggestions would be very helpful.
Thank you
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|