Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VB.NET应请求创建新进程_Vb.net_Visual Studio 2012_Process_Undefined_Createprocess - Fatal编程技术网

VB.NET应请求创建新进程

VB.NET应请求创建新进程,vb.net,visual-studio-2012,process,undefined,createprocess,Vb.net,Visual Studio 2012,Process,Undefined,Createprocess,使用函数创建未定义数量的进程时遇到问题 Function CreateJobProcess(ByVal Name, ByVal ffmpegpath, ByVal params) Try Dim Job As New Process Job.StartInfo.UseShellExecute = False Job.StartInfo.CreateNoWindow = True Jo

使用函数创建未定义数量的进程时遇到问题

Function CreateJobProcess(ByVal Name, ByVal ffmpegpath, ByVal params)
        Try
            Dim Job As New Process

            Job.StartInfo.UseShellExecute = False
            Job.StartInfo.CreateNoWindow = True
            Job.StartInfo.RedirectStandardError = True
            Job.StartInfo.FileName = ffmpegpath
            Job.StartInfo.Arguments = params
            Job.Start()

            Return Job.Handle

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        Return Nothing

    End Function
该函数根据所选的listview条目从1调用到多次,因此我需要为每个进程指定不同的名称

对于每个流程,我需要:

1.创建的新进程的名称我必须从进程中读取标准错误。 2.创建的新流程的句柄

附言


有可能从进程句柄中获取标准错误?

首先,应该启用Option Strict以避免某些类型的错误

您并不需要一个名称,我认为它是指一个变量,但您确实希望保留流程引用,以便在完成时处理它并读取StdErr和StdOut

如果您计划处理StdOut,则需要添加一个处理程序,然后在事件中添加一些代码来处理它。使用ErrorDataReceived的处理程序对StdErr执行同样的操作

然后,作业创建者可以返回新流程或将其存储在列表中

Private Sub CreateNewJob(ffmpegpath As String, params As String)
    Dim P As New Process
    With P.StartInfo
        .UseShellExecute = False
        .CreateNoWindow = False
        .RedirectStandardOutput = True
        .FileName = ffmpegpath 
        .Arguments = params 
    End With

    AddHandler P.OutputDataReceived, AddressOf _OutputDataReceived
    jobs.Add(P)
    P.Start()

End Sub
我会在creator中添加一个Try/Catch,并将其构造为一个函数,如果由于某种原因失败,则返回进程或什么也不返回。作为一项功能:

Dim p As Process = CreateNewJob("file path", "job args")
If p IsNot Nothing Then
    jobs.Add(p)
End If
您没有名称,但jobsN提供了一个引用,因此您可以在完成这些操作后处置它们jobsN.HasExited=True。它提供了一种简单的方法,可以知道您同时运行了多少个,这样您就不会一次启动太多

用于处理输出的事件处理程序:

Private Sub _OutputDataReceived(sender As Object, 
           e As DataReceivedEventArgs)
   ' e.Data will be the output from the child process
End Sub

我想已经完成了。。。另一个问题。。。也许我可以用字典查个名字
Private Sub _OutputDataReceived(sender As Object, 
           e As DataReceivedEventArgs)
   ' e.Data will be the output from the child process
End Sub