lundi 11 mai 2015

Do function right after a proccess ends

Clicks on button

  1. Sbagen process (An open source software) runs at background.
  2. Label2.Text = "Running"
  3. Sbagen process ends automatically after the job done.
  4. Now this is the place I want to edit. I want my software change Label2.Text to "Finished" right after "Sbagen" process ends. How can I achieve this? Tried endless things.

SOLUTION:

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  ...
        AddHandler timer_watcher.Tick, AddressOf TimerEvent
        timer_watcher.Interval = TimeSpan.FromSeconds(1).TotalMilliseconds
        timer_watcher.Start()
    End If
End Sub

Public Sub TimerEvent(sender As Object, e As EventArgs)
    Dim p() As Process = System.Diagnostics.Process.GetProcessesByName("sbagen")
    If p.Length = 0 Then
        timer_watcher.Stop()
        Label2.Text = "Çevrildi!"
    End If
End Sub

Aucun commentaire:

Enregistrer un commentaire