2016-11-03 2 views
0

timer_tick 이벤트 조건이 일치하는지 확인하여 다음 텍스트를 음성 및 오디오 파일 재생으로 트리거하는 코드는 다음과 같습니다. 그러나 조건이 충족되면 예상대로 결과가 얻어 지지만 프로그램이 멈 춥니 다.Timer_Tick이 프로그램을 고정시킵니다.

또한 이러한 조건이 일치 할 때 팝업 메시지 상자를 추가하는 방법. 오디오 파일이나 음성이 반복되는 것은 좋지만 타이머 틱이 계속되면 메시지 상자를 반복해서 열지 않습니다.

private void timer1_Tick(object sender, EventArgs e)  
{ 
    label_time1.Text = DateTime.Now.ToString("hh:mm:ss tt"); 
    label6.Text = DateTime.Now.ToShortDateString(); 
    if (((DateTime.Now.ToString("hh:mm tt") == (textBox_ordertostart.Text) && (DateTime.Now.ToShortDateString() == dateTimePicker2.Value.ToShortDateString()) && (checkBox_delivery.CheckState == 0) && (checkBox_pickup.CheckState != 0)))) 
    { 
     comboBox_suburb.Enabled = false; 
     checkBox_delivery.Enabled = false; 
     mplayer = new SoundPlayer(WindowsFormsApplication17.Properties.Resources.good_morning); 
     mplayer.Play(); 


     pbuilder.ClearContent(); 

     pbuilder.AppendText("Pickup order time start now"); 


     txt2speech.Speak(pbuilder); 
     pbuilder.AppendBreak(PromptBreak.Medium); 
    } 
+0

[SpeechSynthesizer 클래스] (https://msdn.microsoft.com/en-us/library/office/system.speech.synthesis.speechsynthesizer.aspx)를 사용하고 있습니까? 그렇다면'Speak' 대신'SpeakAsync'를 시도하십시오. – adv12

+0

좋습니다. 그게 정말 고마워. messagebox에 대한 아이디어가 있습니까? –

답변

0

Speak 기능을 사용할 때 SpeechSynthesizer가 프로그램을 유지합니다. Speak() 대신 SpeakAsync()을 사용해보십시오. 또는 틱 내의 기능이 프로그램의 UI를 차단하지 않도록하려면 틱을 실행하는 새 스레드를 시작할 수 있습니다.

관련 문제