AutoCAD.NET文档事件:DocumentActivationChanged

关于DocumentCollection 的 DocumentActivationChanged 事件,查阅资料找到的解释是:活动文档窗口失活或销毁时触发。作为文档级别的事件,我理解的是要切换或者打开关闭文档才会触发该事件,所以在做层表事件响应的时候订阅了该事件,用以刷新图层列表。

后来发现:在进行一些图元编辑操作(比如移动多段线节点啥)的时候,鼠标会异常卡顿。最开始很纳闷,以为是订阅了 Object 相关事件造成的,专门控制变量做了好一阵测试,最后发现上述事件才是罪魁祸首,以下测试代码:

        [CommandMethod("TTT")]
        public void Test()
        {
            Application.DocumentManager.DocumentActivationChanged +=
                DocumentManager_DocumentActivationChanged;
        }
        private int count = 0;
        private void DocumentManager_DocumentActivationChanged(object sender, DocumentActivationChangedEventArgs e)
        {
            count++;
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(
                "DocumentActivationChanged,Count: " + count + Environment.NewLine);
        }

然后结果是这样:

在这里插入图片描述
我他喵的,随便拖一个节点触发几百次,不卡才怪了。所以这个事件并不仅仅是文档级别,应该是某些窗口刷新都会触发,慎用。
然后,顺便测试了下文档级别全部事件(13个)的触发顺序:

		public void Test()
        {
            Application.DocumentManager.DocumentCreated += DocumentManager_DocumentCreated;
            Application.DocumentManager.DocumentActivated += DocumentManager_DocumentActivated;
            Application.DocumentManager.DocumentBecameCurrent += DocumentManager_DocumentBecameCurrent;
            Application.DocumentManager.DocumentCreateStarted += DocumentManager_DocumentCreateStarted;
            Application.DocumentManager.DocumentCreationCanceled += DocumentManager_DocumentCreationCanceled;
            Application.DocumentManager.DocumentDestroyed += DocumentManager_DocumentDestroyed;
            Application.DocumentManager.DocumentLockModeChangeVetoed += DocumentManager_DocumentLockModeChangeVetoed;
            Application.DocumentManager.DocumentLockModeChanged += DocumentManager_DocumentLockModeChanged;
            Application.DocumentManager.DocumentLockModeWillChange += DocumentManager_DocumentLockModeWillChange;
            Application.DocumentManager.DocumentToBeActivated += DocumentManager_DocumentToBeActivated;
            Application.DocumentManager.DocumentToBeDeactivated += DocumentManager_DocumentToBeDeactivated;
            Application.DocumentManager.DocumentToBeDestroyed += DocumentManager_DocumentToBeDestroyed;
            Application.DocumentManager.DocumentActivationChanged +=DocumentManager_DocumentActivationChanged;
        }
        private int step = 0;
        private string fileName=@"d:test.txt";

        private void DocumentManager_DocumentToBeDestroyed(object sender, DocumentCollectionEventArgs e)
        {
            step++;
            HtFileHelper.AppendText("step " + step + " :DocumentToBeDestroyed", fileName);
        }
        //后面就不一一列出....

文档从打开到关闭,大致顺序如下:

顺序事件
step 1 :DocumentLockModeWillChange
step 2 :DocumentLockModeChanged
。。。。。。
step 9 :DocumentActivationChanged
。。。。。。
step 26 :DocumentCreateStarted
。。。。。。
step 29 :DocumentToBeDeactivated
。。。。。。
step 34 :DocumentActivationChanged
step 35 :DocumentCreated
step 36 :DocumentActivated
step 37 :DocumentBecameCurrent
。。。。。。
step 55 :DocumentActivationChanged
。。。。。。
step 62 :DocumentBecameCurrent
。。。。。。
step 65 :DocumentToBeDestroyed
step 66 :DocumentDestroyed

省略号是Step1+Step2组合的重复,意义不大,就删掉了,测试并不严谨,仅供参考。


最后,想起之前一个前辈的告诫:慎用事件,在你不确定的时候

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
AutoCAD .net开发人员手册中文版 文档介绍: 当前版本为20101128版,为第一个CHM版本,如需更新版本,请及时关注http://www.01vb.com,也可以查看CHM文件中的前言部分的版本通知。 因本版本制作仓促,还有如下不完善的内容。 1、还有一章内容没有翻译完成; 2、目录部分和索引部分还是英文版本,但具体页面中全部是中英文对照(有些在提示中有些在翻译上面)。 本《AutoCAD .NET 开发人员手册》由01VB编程站翻译并提供,版权所有,原英文版本版权归原版权所有者所有。本手册为免费版本,可在网上随意发送,但必须注明出处(01VB编程站及网站链接http://www.01vb.com)及翻译者。 序言 自从 AutoCAD 支持使用 .NET 开发以来,所有关于 .NET 的官方开发资料全部是英文版本,给国内开发者的学习带来了一定的阻碍,为了给广大 .NET 爱好者提供更多方便,于是决定翻译一部分资料。 因本人英文水平及CAD二次开发水平有限,翻译的资料中也许有表达不清楚的地方,请大家谅解,也可以在资料底部找到留言的链接,给我留言或直接点击QQ联系我。 01VB编程站是一个非营利性的网站,但是,网站要生存,必须有经济来源。因此,本人在本手册中的投放了广告,但是,广告都是在正文内容的底部,不影响阅读。原则上我不鼓励大家点击上面的广告,除非真的对广告内容感兴趣。因广告给您带来的不便,还望谅解。 最近一段时间,老婆一直生病,始终没有痊愈,在此,我希望老婆能快点儿好起来, 并想对她说一句:老婆,别哭,好好养病,病痛在你身,也疼在我心。你累了,我会背你;钱花光了,我会去挣,身体是第一位的。如果你也想给我老婆送上祝福,请留言,谢谢!(2010.11.24) 翻译历史 2010年8月中旬 开始,期间由于本人生病,中断了几天,还有部分内容没有翻译完成,仍然在翻译中。 11.6 更新《图层状态管理器的使用》部分。 11.07 更新《文字样式》部分 11.08 更新完《创建和编辑AutoCAD图元》这章。 11.11 更新 《标注的概念》 部分 11.12 更新《创建标注》部分 11.15 更新完 《创建引线和注释》 部分 11.20 更新完《形位公差》 部分 11.24 更新到 《在三维空间中编辑 》 11.28 修正手册中的脚本错误,进行CHM格式文档的制作并在01VB编程站首发。 感谢 《AutoCAD .NET 开发人员手册》的翻译过程得到 明经通道 网站 "明经 AutoCAD.NetApi 群"中许多网友的帮助,像 MCCAD、雪山飞狐、Still等等,另外还有其它人记不清楚了,因为太多太多,总之两个字,谢谢。 版权 本开发人员手册版权属01VB编程站网站所有。 翻译者:黄明新(平凡)

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值