Process.Start returns null

前端 未结 4 1332
情深已故
情深已故 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:18

    That won't even compile (definite assignment). As a method variable, proc is local only to the declaring method(/scope) - i.e. button2_Click, which explains why you can't retain values. If proc is meant to persist between calls, promote it to a field (per-instance variable):

    Process proc;
    private void button2_Click(object sender, EventArgs e)
    {
        if (proc != null)
        ...
    

提交回复
热议问题