我正在創建一個windows phone 8.1應用程序。當應用程序啓動時,應用程序會提示用戶撥打特定的電話號碼。它用聲音做到這一點。通過應用程序告知說明後,顯示電話呼叫對話框。 這是代碼:如何避免異步方法windows phone 8.1
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
StartSpeaking("Please call number !");
CallDialog();
}
private async void StartSpeaking(string text)
{
MediaElement mediaElement = this.media;
// The object for controlling the speech synthesis engine (voice).
var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
// Generate the audio stream from plain text.
SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync(text);
// Send the stream to the media object.
mediaElement.SetSource(stream, stream.ContentType);
mediaElement.Play();
}
private async void CallDialog()
{
Windows.ApplicationModel.Calls.PhoneCallManager.ShowPhoneCallUI("123", "123");
var messageDialog = new Windows.UI.Popups.MessageDialog("call ended", "Text spoken");
await messageDialog.ShowAsync();
}
的問題是,我必須用synth.SynthesizeTextToStreamAsync方法是異步方法這麼叫的對話框顯示出來,據說文本之前。我怎樣才能避免這種情況?
是的,我明白這一點,但即使我去這樣,當應用程序啓動時,我仍然可以調用對話框,而不是在請求之前撥打號碼。 – n32303 2014-09-06 17:56:32