0

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?

Filburt
  • 17,626
  • 12
  • 64
  • 115
Zed Machine
  • 67
  • 1
  • 10
  • possible duplicate of [VB.NET: How to maintain main form control during loops in other sub?](http://stackoverflow.com/questions/28265331/vb-net-how-to-maintain-main-form-control-during-loops-in-other-sub) – Ňɏssa Pøngjǣrdenlarp Feb 02 '15 at 13:42
  • no it's another question... how can i send key to program without window?? – Zed Machine Feb 02 '15 at 14:56
  • noone can help me? i have found only a way to close ffmpeg but by process.kill()... i need to send command to properly close or pause ffmpeg – Zed Machine Feb 02 '15 at 20:01

1 Answers1

0

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

Zed Machine
  • 67
  • 1
  • 10