Process.Start returns null

前端 未结 4 1349
情深已故
情深已故 2020-12-16 12:05

i am writing a program that launches a random file in a directory. the file can be of any time, but mostly video or image files. each time i launch a file i want to close th

4条回答
  •  盖世英雄少女心
    2020-12-16 12:29

    EDIT: Thanks to leppie's comment, I suspect I know the answer: my guess is that you're "starting" something like an image, and it's reusing an existing process to open the document instead of creating a new one.

    I've reproduced this with this simple test app:

    using System;
    using System.Diagnostics;
    
    public class Test
    {
        static void Main()
        {
            Process proc = Process.Start("image.tif");
            Console.WriteLine(proc == null);
        }
    }
    

    This prints "true" because it's using dllhost.exe to host the Windows Image Viewer, rather than creating a new process.

提交回复
热议问题