我在c#UWP中有这个简单的代码,其中使用Windows.Media.SpeechSynthesis类,应用程序合成第一个字符串,我的问题是在第一个合成完成后合成第二个字符串。我知道有可能通过创建一个包含str1 + str2的唯一字符串,但运行此代码的场景更复杂,这是不可能的。(对不起我的英语水平低)
data <- [!(data$DES6=="F001"),]
答案 0 :(得分:2)
与往常一样,让async
方法返回void
代替Task
或Task<T>
是个坏主意。
当您返回Task
时,您只需添加ContinueWith
的续集:
public MainPage()
{
this.InitializeComponent();
string str1 = "weather data";
Task talkingTask = talk(Textmeteo);
string str2 = "hello world";
talkingTask = talkingTask.ContinueWith(completedTask => talk(str2));
}
public async Task talk(string text)
{
// await...
}
答案 1 :(得分:2)
让方法talk
返回Task
而不是void
。
public MainPage()
{
this.InitializeComponent();
MakeTalk();
}
private async void MakeTalk()
{
// Surround by a try catch as we have async void.
string str1 = "weather data";
await talk(Textmeteo);
string str2 = "hello world";
await talk(str2);
}
public async Task talk(string text)
{
// [...]
}