Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

CancellationToken callback was not executed immeditely

$
0
0

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?






Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>