how to cancel Process.CloseMainWindow

Posted on 2012-08-27
Medium Priority
Last Modified: 2012-09-02

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?
Question by:Tina_Bhole
  • 2
LVL 83

Expert Comment

ID: 38339833
Check the file last modified time to see if file was saved.

Author Comment

ID: 38343636
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...
LVL 83

Accepted Solution

CodeCruiser earned 800 total points
ID: 38344758
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


Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question