我有以下代码:
public void Test(IMyInterface iInterface)
{
  iInterface.CallMethod ( );
}
Run Code Online (Sandbox Code Playgroud)
哪个工作正常.但是,如果我将代码更改为线程:
private IMyInterface myInterface;
public void Test(IMyInterface iInterface)
{
  myInterface = iInterface;
  new Thread ( new ThreadStart ( CallInterfaceMethod) ).Start ( );
}
public void CallInterfaceMethod ( )
{
  myInterface.CallMethod ( )
}
Run Code Online (Sandbox Code Playgroud)
当我使用线程时,我收到异常:
无法将"System .__ ComObject"类型的COM对象强制转换为接口类型"IMyInterface".此操作失败,因为对于具有IID"{GUID}"的接口的COM组件的QueryInterface调用由于以下错误而失败:不支持此类接口
但是应该支持接口就好了吗?有人对这里发生的事情有任何想法吗?
我开发了一个外部WPF应用程序来生成c#中的绘图.我已经能够使用Autodesk.AutoCAD.Interop绘制,维度,添加块以及应用程序所需的所有其他内容,但是我似乎无法填充标题块或生成部件列表.
我见过的所有示例都基于要求应用程序作为AutoCAD内部插件运行的机制.事实是,使用ModelSpace.InsertLine插入一行使用的是一行或两行代码,现在,它至少有8行代码!
有没有办法使用Autodesk.AutoCAD.Interop实现此功能?或者有没有办法将interop与可以从外部exe调用的插件结合使用?
任何关于此的指示将不胜感激.
谢谢.
编辑 说明:
// before - Draw Line with Autodesk.AutoCAD.Interop
private static AcadLine DrawLine(double[] startPoint, double[] endPoint)
{
    AcadLine line = ThisDrawing.ModelSpace.AddLine(startPoint, endPoint);
    return line;
}
// Now - Draw line with Autodesk.AutoCAD.Runtime
[CommandMethod("DrawLine")]
public static Line DrawLine(Coordinate start, Coordinate end)
{
    // Get the current document and database 
    // Get the current document and database
    Document acDoc = Application.DocumentManager.MdiActiveDocument;
    Database acCurDb = acDoc.Database;
    // Start a transaction
    using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
    {
        // Open …Run Code Online (Sandbox Code Playgroud) 我正在使用C#中的Windows窗体编写一个程序来模拟3d对象,然后应该从.NET框架中打开AutoCAD来绘制对象,我正在尝试找出最好的方法.
我之前尝试过使用COM从.NET打开AutoCAD,但我想知道是否有一种方法可能没有以这样的界面支持错误结束,就像我尝试过的每一条道路一样(打开一个图纸,打开AutoCAD)使用COM等)已经结束而没有结果.有什么建议?