WPF application, I have
public CancellationTokenSource cTokenSource; public static CancellationToken cToken;
cTokenSource = new CancellationTokenSource();
cToken = cTokenSource.Token;
async Task Consumer() { try { dddd d = new dddd(ts); Dictionary<string, string> dict = d.RunScript(cToken);
Then in a cancel button event.
private void Cancel_Click(object sender, RoutedEventArgs e) { cTokenSource.Cancel(); }I registered the call back in RunScript method.
string s = "a very long paragraph"; m_VoiceResource.PlayTTS(s); cToken.Register(() => { m_VoiceResource.Stop(); // stop any activity on m_VoiceResource }However after I clicking the cancel button, the code didn't reach m_VoiceResource.Stop() immediately. I want to interrupt the play text to speech, which is PlayTTS. Did I block any thread? I don't think so but why?