我正在使用TaskPane用C#编写PowerPoint加载项。
我现在想在窗格上打印一些内容-等待5秒钟-然后打印其他内容。
我在等待过程中遇到问题。
如果使用System.Threading.Thread.Sleep(5000)
,则冻结所有PowerPoint界面,而不仅冻结我的窗格。PowerPoint界面和我的任务窗格是同一线程
如果使用System.Timers.Timer
,则创建第二个线程,并触发一条错误消息,提示我正在尝试访问其他线程上的对象。
这是我的第二种情况的代码:
private void waitThisTime(int givenTime)
{
timer = new System.Timers.Timer(givenTime);
timer.Elapsed += OnTimedEvent;
timer.AutoReset = false;
timer.Enabled = true;
}
private void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
{
DisplayMessage(currentState); // DisplayMessage modifies textbox and button displayed on the panel
}
您知道如何仅冻结面板而不触发异常吗?
噜噜哒
相关分类