定时提示
能不能定义一个timer,每隔一定时间在命令行写入时间实现报时功能呢?我尝试写过一个,但是timer事件里面取不到editor 你的代码?试下文档加锁 <p>写一段利用timer的Elapsed事件在命令行里写一些信息的代码看看</p> editor试过了,有问题,呵呵Com调用的方式还可以,不过命令提示会消失掉 :(
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using TlsCad.Trans;
using Autodesk.AutoCAD.EditorInput;
using System.Reflection;
namespace TlsCad
{
class Work
{
public Document _doc;
private object _acUtility;
static Type _acUtilityType;
private Timer t;
private bool m_Starting = false;
public Work(Document doc)
{
_doc = doc;
object acDoc = _doc.AcadDocument;
Type acDocType = Type.GetTypeFromHandle(Type.GetTypeHandle(acDoc));
_acUtility = acDocType.InvokeMember("Utility", BindingFlags.GetProperty, null, acDoc, new object);
_acUtilityType = Type.GetTypeFromHandle(Type.GetTypeHandle(_acUtility));
t = new Timer(DoWork, null, 500, 3000);
}
public void DoWork(object sender)
{
if (!_doc.IsDisposed)
{
if (!m_Starting)
{
m_Starting = true;
if (_doc.Editor.IsQuiescent)
{
try
{
_acUtilityType.InvokeMember
(
"prompt",
BindingFlags.InvokeMethod,
null,
_acUtility,
new object[] { DateTime.Now.ToString() + "\r\n" }
);
}
catch
{ }
}
m_Starting = false;
}
}
}
}
}
public static void Test()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Work w = new Work(doc);
}
页:
[1]