I'm working on a video converter and I wanted to be able to stop or pause ffmpeg by pressing a button. Googleing I have found a way but it's not working. basically I Start ffmpeg on a background worker in this way:
Private Sub bw_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
Dim Proc As New Process
Proc.StartInfo.UseShellExecute = False
Proc.StartInfo.RedirectStandardError = True
Proc.StartInfo.RedirectStandardOutput = True
Proc.StartInfo.FileName = current_ffmpeg_path
Proc.StartInfo.Arguments = input_params
Proc.StartInfo.CreateNoWindow = True
Proc.Start()
[do things...]
then inside a loop I place an if to pause ffmpeg:
If (pause = 1 Or pause = 2) Then
AppActivate(Proc.Id)
SendKeys.SendWait("^(s)")
SetForegroundWindow(Me)
pause = 0
End If
but it's not working.. maybe cause of AppActivate that need a window to work while instead ffmpeg is running without it. There is another way? maybe not with sendkeys?
SOLVED. It's not possible use SendKeys for a process without a window.. use instead NtSuspendProcess and NtResumeProcess..
More information googling about:
p/invoke NtResumeProcess/NtSuspendProcess which are callable platform APIs