我有一個類來處理它啓動的線程中的一些實時動作。在這個應用程序中還有其他的遊戲,因爲它非常複雜。當這個RT動作開始時,我需要彈出一個窗口並在完成時關閉它。聽起來很簡單。線程UI和噩夢
當這個動作開始和停止時,我會鉤住一些事件。在這些事件處理程序中,我放置代碼:
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'?什麼級別?添加一些上下文! – Blindy 2011-06-06 22:06:00