C# cancel a long running task that not a loop
问题 I am new to c# task, what I want to do is convert downloadThread = new Thread(DownLoadFile); downloadThread.Start(); to task like var t = Task.Factory.StartNew(DownLoadFile); I also knew use CancellationTokenSource to cancel. But examples I saw are all long loop running thread, like for, foreach, while, and check IsCancellationRequested to cancel a task in loop. if (ct.IsCancellationRequested) { break; } but my long running task is to download a file from ftp, GetFile is from third party dll.