后台线程不允许操作界面,解决方案委托主线程来操作,在winform中用控件的Invoke方法。CAD插件里,可以用下面两种方法来实现:
方法一(推荐):
//主线程: System.Threading.SynchronizationContext ctx = null; ctx = Autodesk.AutoCAD.Runtime.SynchronizationContext.Current; if(ctx == null) { ctx = new Autodesk.AutoCAD.Runtime.SynchronizationContext(); } //子线程: ctx.Post(HandlerMethod,objectData);
方法二:
//主线程: System.Windows.Forms.Control mainControl; mainControl = new System.Windows.Forms.Control(); mainControl.CreateControl(); //子线程: mainControl.Invoke(new Action()) =>{HandlerMethod,objectData}));
标签:插件,AutoCAD,mainControl,SynchronizationContext,ctx,System,多线程 From: https://www.cnblogs.com/yzeng/p/18051661