how to cancel Process.CloseMainWindow


I have declared a process as follows:

                proc = Process.Start(filename)

I have a button on a form which allows user to close the file as follows:
On btnclose.Click event I have written:


Proc.CloseMainWindows() allows user to save the file before closing.


I want to enable few buttons on the form after the file is closed , but keep the buttons disabled if the user hits Cancel in the above window.
Could some one please help me with this? How do I code for Cancel button in the above window?
Who is Participating?
Yes you can differentiate between No and Cancel by checking if the process is still active.

You can check the proc.HasExited property which will be false if the process is still active
Check the file last modified time to see if file was saved.
Tina_BholeAuthor Commented:
Hi CodeCruiser,

Thanks for your input but this logic is not working for me. Because I want to trace the Cancel event in the 'Save As' window.
The possibilities could be:

User hits Yes :       file was saved before closing
                               condition : (last modified > last open)

User hits No :        file was not saved before closing
                               condition: (last modified < last open)

User hits Cancel: file is still open
                               condition: (last modified < last open)

So, how do we differenciate between 'No' and 'Cancel' condition? How to we check if the file is still open or user has hit 'No' in the 'Save As'  window and closed file without saving?

Or is it better to see if the process is still active? If so, how do we check?

I am sorry if I have ignored something very important in your comment or failed to understand it. My brain has just stopped working on this now..

Could you please clarify...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.