Diadem 发表于 2009-12-19 15:43:00

打开文件的问题,请高手指点

一直对的运行环境没有搞清楚,希望高手讲解一下。
我的代码如下,编译之后用netload加载到CAD2008中,执行到打开文件的时候,老是报致命错误,然后CAD2008退出了。
      
      public void StartWatch()
      {
            System.Windows.Forms.MessageBox.Show("测试开始", "开始监听!");
            try
            {
                IPEndPoint e = new IPEndPoint(IPAddress.Any, 1234);
                Udp = new UdpClient(e);
                Udp.EnableBroadcast = true;
                Udp.BeginReceive(new AsyncCallback(Udp_ER), Udp);
            }
            catch { }
      }
      
      public static void OpenXP()
      {
            try
            {
                //此处老是报错
                Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(fileName);
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message, "打开文件出错!");
            }
      }
      protected static string fileName;
      
      public static void Udp_ER(IAsyncResult ar)
      {
            byte[] msg = null;
            IPEndPoint addr = null;
            try
            {
                msg = Udp.EndReceive(ar, ref addr);
                Udp.BeginReceive(new AsyncCallback(Udp_ER), null);
            }
            catch (System.Exception ex)
            {
            }
            if (msg != null && msg.Length > 0)
            {
                //接受其他程序发送过来的网络信息,信息为:文件路径信息,绝对正确。
                System.Windows.Forms.MessageBox.Show(Encoding.Default.GetString(msg), "收到信息!");
                fileName = Encoding.Default.GetString(msg);
                OpenXP();
            }
      }

雪山飞狐_lzh 发表于 2009-12-19 16:13:00

文档加锁试试

Diadem 发表于 2009-12-19 16:36:00

还没有打开文档,怎么加锁呢?
页: [1]
查看完整版本: 打开文件的问题,请高手指点