3
我從main方法調用:如何在C#中將異步方法與同步方法結合起來?
public MainPage()
{
Text_to_Speech.changetospeech("Welcome to Nepal!", newmedia).Wait();
mytxtblck.Text="Hello from Nepal!"
}
我真正想要做的是Wait
直到「歡迎來到尼泊爾」正在在mytextblck
發言,然後寫「你好」。
我已經去了幾個線程和工作,但沒有什麼可以使它的工作。
public async static Task changetospeech(string text, MediaElement mediaa)
{
var synth = new SpeechSynthesizer();
var voices = SpeechSynthesizer.AllVoices;
synth.Voice = voices.First(x => x.Gender == VoiceGender.Female);
SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync(text);
MediaElement media = mediaa;
media.SetSource(stream,stream.ContentType);
media.Play();
}
哇謝謝老兄它就像一個魅力... – Learner
會不會'Task.FromResult'比'TaskCompletionSource'好# –
@MrinalKamboj:你究竟如何用它來解決手頭的問題?它如何幫助你異步等待事件發生? –