Cris Cris - 1 year ago 75 Question

handle when user closes or saves a file after Diagnostics.Process.Start

I have a Windows app that opens a file with Diagnostics.Process.Start(path), after opening the file user can modify it and I need to save it to db using a WCF. Is it possible to detect from the app that started the process when the file has been saved or closed by the user?
Thank you for your help

Answer Source

Yes, you can add an exit event listener to the process, and then do whatever processing that's needed after the user has exited the program. Here's a bare-bones example of the concept:

Public Class Form1
    Private WithEvents p As New System.Diagnostics.Process
    Public Event pEnd As EventHandler

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        p.StartInfo.FileName = "notepad.exe"
        p.EnableRaisingEvents = True
    End Sub

    Private Sub p_Ended(ByVal sender As Object, ByVal e As System.EventArgs) Handles p.Exited
    End Sub
End Class