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 the previous opened one.
the code is:
string FolderSelected = "";
string FileName = "";
Process proc;
List<string> FilesDisplayed = new List<string>();
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
if (FolderSelected == string.Empty)
FolderSelected = Properties.Settings.Default.FilesDefaultFolder;
if (proc != null)
{
proc.CloseMainWindow();
proc.Close();
}
FileName = FetchRandomFile();
proc = Process.Start(FileName);
}
the problem is, that i keep getting proc = null (the file is launched properly) and i cannot fetch the previously opened process in order to close it. I know that .NET reuses processes and thats why it returns Null but i need to override this behavior.
please help,
Guy.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…