如何检测是否Visual Studio IDE中使用VSPackage的关闭? [英] How to Detect if Visual Studio IDE is closing using VSPackage?

查看:275
本文介绍了如何检测是否Visual Studio IDE中使用VSPackage的关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个VS包,我需要存储的时候,当用户开始我的包,当用户关闭Visual Studio的。

I'm writing a VS Package where I need to store the time when the user start my package, and when the user close the Visual Studio.

问题是的,我不知道如何获得Visual Studio的闭幕活动。 ?谁能给我如何当VS正在关闭探测到任何信息。

The problem is, I don't know how to get the closing event for the Visual Studio. Can anyone give me any information about how to detect if the VS is closing?

请注意:当我从网上搜索,我得到了下面类似的问题,以我的:< A HREF =http://stackoverflow.com/questions/2385146/how-do-you-cancel-a-toolwindowpane-or-visual-studio-ide-close-operation-via-a-vs>你怎么了取消通过VSPackage的一个ToolWindowPane或Visual Studio IDE关闭操作?的,但是当我尝试它,这个解决方案是检测和关闭时包窗口中做一些事情,而当Visual Studio是关闭无法检测。

Note: When I search from the internet, I got the following similar problem to mine: How do you cancel a ToolWindowPane or Visual Studio IDE close operation via a VSPackage?, but when I try it, this solution is to detect and do something when the Package window is closed, and cannot detecting when the Visual Studio is closed.

任何帮助,非常感谢。

感谢

推荐答案

只是,清楚,并关闭了这个问题。
这是代码的快照,以检查是否VS正在关闭:

Just to make it explicit and close this problem. This is the snapshot of code to check if VS is closing:

// Create 2 variables below
private DTE2 m_applicationObject = null;
DTEEvents m_packageDTEEvents = null;

然后在初始化补充一点:

Then in Initialize add this:

// Link the Event when VS CLOSING                
m_packageDTEEvents = ApplicationObject.Events.DTEEvents;
m_packageDTEEvents.OnBeginShutdown += new _dispDTEEvents_OnBeginShutdownEventHandler(HandleVisualStudioShutDown);



另外两个,你需要的方法:

Two other methods that you need:

 public DTE2 ApplicationObject
 {
        get
        {
            if (m_applicationObject == null)
            {
                // Get an instance of the currently running Visual Studio IDE
                DTE dte = (DTE)GetService(typeof(DTE));
                m_applicationObject = dte as DTE2;
            }
            return m_applicationObject;
        }
  }

public void HandleVisualStudioShutDown()
{
    MessageBox.Show("Exiting Visual Studio. Bye");
}

这篇关于如何检测是否Visual Studio IDE中使用VSPackage的关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆