我正在创建一个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