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
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)
...