【发布时间】:2011-06-06 19:59:12
【问题描述】:
我有一个类在它启动的线程中处理一些实时操作。由于它非常复杂,因此在此应用程序中还有其他问题。当这个 rt 动作开始时,我需要弹出一个窗口并在完成后关闭它。听起来很简单。
当这个动作开始和停止时,我会挂钩一些事件。在这些事件处理程序中,我放置了代码:
private void Voice_SpeakStarted(object sender, TMSpeakStartedEventArgs e)
{
InfoWindow = new Form();
InfoWindow.Show();
}
/// <summary>
/// this is the event handler speaking stops
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Voice_SpeakCompleted(object sender, TMSpeakCompletedEventArgs e)
{
if (InfoWindow.InvokeRequired)
{
InfoWindow.Invoke(new Action(() =>
{
InfoWindow.Close();
}));
InfoWindow.Hide();
}
}
有时我收到线程已终止的错误。 (调用该方法时出错。目标线程不再存在。)
我似乎总是让窗口显示出来。我似乎无法关闭窗口。
我还看到有时处理程序本身不会被调用。
我非常需要帮助。如果有帮助,我可以发布更多代码。
已编辑 - 添加了更多代码 这就是我开始上课的方式
public void start()
{
//It's already alive, nothing to do
if (alive) return;
//Make sure this is the only place where alive is set to true
alive = true;
Voice.SpeakCompleted += new Speech.TMSpeakCompletedDelegate(Voice_SpeakCompleted);
Voice.SpeakStarted += new Speech.TMSpeakStartedDelegate(Voice_SpeakStarted);
dispatch = new Thread(new ThreadStart(ProcessSayList));
dispatch.Start();
}
类的构造函数是
public AnimationControl(dynamic parent)
{
Parent = parent;
Voice = new Speech();
q = Queue.Synchronized(new Queue(1000));
start();
}
【问题讨论】:
-
ProcessSayList是什么?什么级别?添加一些上下文!
标签: winforms multithreading user-interface