zoukankan      html  css  js  c++  java
  • (学)关于开发插件过程中的几点事项

    纯属个人工作记录。

    1、插件OnConnection事件执行两次,结果导致其中的部份关联事件的方法执行了多次,学习http://sifang2004.cnblogs.com/archive/2006/06/26/436178.html,加上了 if (xxxxxxxxxxxx)这样一行代码问题解决。   

    代码
    1 public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
    2 {
    3     _applicationObject = (DTE2)application;
    4     _addInInstance = (AddIn)addInInst;
    5     if (connectMode == ext_ConnectMode.ext_cm_AfterStartup || connectMode == ext_ConnectMode.ext_cm_Startup)
    6     {
    7        //事件关联代码
    8     }
    9 }

    2、插件需要以管理员的身份执行,但通过插件判断提示VS需要以管理身份运行后原来所打开的VS未能关闭。

         由原来的

         VistaSecurity.RestartElevated();
         Environment.Exit(0);

         改成异步后问题解决。

         AsyncEventHandler asy = new AsyncEventHandler(VistaSecurity.RestartElevated);
         asy.Invoke();
         Environment.Exit(
    0);

    代码
    if (VistaSecurity.IsAdmin())
    {
       RegistryKey key 
    = Registry.ClassesRoot.OpenSubKey(@"RegistKey\" + ProductName, true);
       
    try
       {
           key 
    = Registry.ClassesRoot.CreateSubKey(@"RegistKey\" + ProductName);
           key.SetValue(ActiveCode, strKey);
       }
       
    finally
       {
           key.Close();
       }
    }
    else
    {
       AsyncEventHandler asy 
    = new AsyncEventHandler(VistaSecurity.RestartElevated);
       asy.Invoke();
       Environment.Exit(
    0);
    }


     
    public delegate void AsyncEventHandler();

    3、.net平台生来就注定程序员写出来的代码没有任何安全可言,太可怕了。

    4、补充:为什么开发的插件中某些事件未能执行?

        参见 http://social.msdn.microsoft.com/Forums/en-IE/vsx/thread/38381610-398a-42dd-8611-f6d9a596d1fa

  • 相关阅读:
    102/107. Binary Tree Level Order Traversal/II
    110. Balanced Binary Tree
    SQL SERVER select,update,delete使用表别名
    C# 有哪些集合
    C# 流总结
    How ASP.NET MVC Works ? (Artech)
    c#扩展方法
    使用缓存的九大误区
    9中浏览器端缓存
    理解AppDomain和AppPool
  • 原文地址:https://www.cnblogs.com/spymaster/p/1630241.html
Copyright © 2011-2022 走看看