Vb.Net Search The Internet And Wait until Internet Is Closed

Vb.Net Search The Internet And Wait until Internet Is Closed

isocam
Collaborator Collaborator
404 Views
5 Replies
Message 1 of 6

Vb.Net Search The Internet And Wait until Internet Is Closed

isocam
Collaborator
Collaborator

Can anybody help?

 

I am using the following code (as a test only) to do an internet search using Vb.Net (as part of an Inventor VBA macro).

 

Process.Start("https://www.bing.com/search?q=Microsoft")

 

I want to hide the form (using Me.Hide) and then show the form (using Me.Show) once I have closed the Internet browser.

 

Does anybody know how I to modify the code so that it waits until the user closes the internet browser before re-showing the form?

 

Many thanks in advance!

 

Darren

0 Likes
405 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Hi @isocam.  It is not something that I use often, but that code (Process.Start()) is a Function that returns a Process object.  So, if you create a Process type variable ahead of time, then use that line of code to set its value, you will be left with a reference to that Process object.  The Process Class has a few Events that you may be able to use, one of which is process.exited.  You can see an example Sub on that linked page for handling that event.  That should give you the control you are looking for.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

WCrihfield
Mentor
Mentor

I just created a simple little iLogic rule to test this functionality, and it was not working as planned initially, then I realized that I did not specify the additional setting called EnableRaisingEvents, which is needed in this type of scenario.  There can of course be a lot more to it, but this is just a quickie introduction to get you started.

First make sure no other instances of the default text file opening application is currently running.  This example rule just opens a local text file that is located under my C:\Temp\ folder.  I capture the Process that gets started when it opens that text file.  Then I specify True for that setting I mentioned above.  Then I add the specification that the custom Sub routine below is to be ran when that specific event happens to the Process I captured.  When the rule is ran, it opens that text file on my screen, then waits for that event to happen.  When I close that Notepad window using the little X in the upper right hand corner, it then immediately writes the note into my iLogic Log window, and removes the event handler specification again.  A one shot deal.

Sub Main
	oTextEditorProcess = Process.Start("C:\Temp\InvLog.txt")
	oTextEditorProcess.EnableRaisingEvents = True
	AddHandler oTextEditorProcess.Exited, AddressOf oTextEditorProcess_Exited
End Sub

Dim oTextEditorProcess As Process

Sub oTextEditorProcess_Exited(ByVal sender As Object, ByVal e As System.EventArgs)
	Logger.Info("Text Editor Process Just Exited")
	'MessageBox.Show("Text Editor Process Exited.", "Process Exited")
	RemoveHandler oTextEditorProcess.Exited, AddressOf oTextEditorProcess_Exited
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 6

Frederick_Law
Mentor
Mentor
Message 5 of 6

WCrihfield
Mentor
Mentor

Good point.  I did a little testing, and if you do not use that, the remainder of the code will continue running before the process has exited.  If I call that Sub right after adding the handler spec, but before any further code, it will wait at that point in the code for the process to exit, then continue with the rest of the code.  Very handy little detail.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 6

Frederick_Law
Mentor
Mentor

Process.Start run it in parallel (threaded).  So multiple process can be run at the same time.  As long as what hey do doesn't depends on each other.

Managing multiple threads is another topic.

0 Likes