Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.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
C# Process.GetProcessById()引发ArgumentException“;“进程未运行”;在所有线程ID/进程ID上_C#_Exception_Process_Pinvoke_Pid - Fatal编程技术网

C# Process.GetProcessById()引发ArgumentException“;“进程未运行”;在所有线程ID/进程ID上

C# Process.GetProcessById()引发ArgumentException“;“进程未运行”;在所有线程ID/进程ID上,c#,exception,process,pinvoke,pid,C#,Exception,Process,Pinvoke,Pid,无论我尝试使用其中哪一个,Process.GetProcessById().ProcessName都会抛出一个异常,说明所有进程都没有运行 [DllImport("user32.dll", SetLastError = true)] static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId); [DllImport("user32.dll")] static e

无论我尝试使用其中哪一个,
Process.GetProcessById().ProcessName
都会抛出一个异常,说明所有进程都没有运行

    [DllImport("user32.dll", SetLastError = true)]
    static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);

    [DllImport("user32.dll")]
    static extern uint GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);

            for (int x = 0; x < listBox1.Items.Count; x++)
            {
                IntPtr y = new IntPtr(Convert.ToInt32(listBox1.Items[x].ToString()));
                uint processID = 0;
                int procID = Convert.ToInt32(GetWindowThreadProcessId(y, out processID));
                //int procID = Convert.ToInt32(GetWindowThreadProcessId(y, IntPtr.Zero);
                //listBox2.Items.Add(procID);
                listBox2.Items.Add(Process.GetProcessById(procID).ProcessName);
            }
[DllImport(“user32.dll”,SetLastError=true)]
静态外部单元GetWindowThreadProcessId(IntPtr hWnd,out单元lpdwProcessId);
[DllImport(“user32.dll”)]
静态外部单元GetWindowThreadProcessId(IntPtr hWnd,IntPtr ProcessId);
对于(int x=0;x
与EnumWindows和/或EnumChildWindows一起使用如何填写listBox1?您不想使用
processID
而不是返回值吗?是的,谢谢。作为答案,我会点击SolveDrubish API tho,不是吗?当然,您会假设它返回了它所说的内容。我打赌这种情况经常发生。