how to cancel Process.CloseMainWindow

Posted on 2012-08-27
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
    LVL 83

    Expert Comment

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

    Author Comment

    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

    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

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
    This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
    Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
    The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now