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

(Not an Autodesk Employee)