Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

How can I call a function that owns tha overload of Cancellationtoken in another scope?

$
0
0
 public async void TaskDelayTest(CancellationToken token)
        {
            try
            {
                while (LoopCheck)
                {
                    foreach (string word in WordsOfFile)
                    {

                        WordToShow = word;
                        await Task.Delay(time, token);
                        

                    }
                }
            }
            catch (Exception ex)
            {
               
                TaskCanceledException TaskException = new TaskCanceledException("Word Stream Canceled", ex.InnerException);
                throw ex.InnerException;
            }
        }
This is my code. And I want to call this function in another cope (for example in a button_click event). TaskDelayTest() need overload. O enter the overload
Task.Delay(CancellationToken token)

then it says System.Threading.CancellationToken' is a 'type' but is used like a 'variable'. But what it wants in Intellisense is that. So I couldn't figur out how to call this function.

Viewing all articles
Browse latest Browse all 31927

Trending Articles



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