private void btnViewErrorLogFile_Click(object sender, EventArgs e)
{
errorLogFileProcess = Process.Start(AppVars.ErrorLogFilePath);
}
The above opens a text file in notepad. It contains error logs for my application.
I do not want to allow the user to open multiples of this file. So I do not want to have him/her click the button again and open another window of the same file.
How do I check if this file is open? Note: I DO NOT want to close a (or all) notepad.exe processes because the user might have a notepad process open for something else other than my application file (which uses notepad.exe when the file is open).
So again, how do I go about checking whether the process I opened is already opened?
Just had another re-read of your question.
If you want to force the user to close the active instance of Notepad (that you launched) before allowing them to open it again, keep the
errorLogFileProcessinstance around and then recheck it before allowing the command.Could also use the
errorLogFileProcess.HasExitedstate to disable the button so that the Click event is not raised.