本文整理汇总了C#中IWebClient.CancelAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IWebClient.CancelAsync方法的具体用法?C# IWebClient.CancelAsync怎么用?C# IWebClient.CancelAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IWebClient
的用法示例。
在下文中一共展示了IWebClient.CancelAsync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetupTransferProgress
static Timer SetupTransferProgress(IWebClient webClient, ITransferProgress transferProgress) {
var lastTime = Tools.Generic.GetCurrentUtcDateTime;
long lastBytes = 0;
transferProgress.Progress = 0;
transferProgress.FileSizeTransfered = 0;
webClient.DownloadProgressChanged +=
(sender, args) => {
var bytes = args.BytesReceived;
var now = Tools.Generic.GetCurrentUtcDateTime;
transferProgress.Progress = args.ProgressPercentage;
transferProgress.FileSizeTransfered = bytes;
if (lastBytes != 0) {
var timeSpan = now - lastTime;
var bytesChange = bytes - lastBytes;
if (timeSpan.TotalMilliseconds > 0)
transferProgress.Speed = (long) (bytesChange/(timeSpan.TotalMilliseconds/1000.0));
}
lastBytes = bytes;
lastTime = now;
};
webClient.DownloadFileCompleted += (sender, args) => { transferProgress.Completed = true; };
var timer = new TimerWithElapsedCancellation(500, () => {
if (!transferProgress.Completed
&& Tools.Generic.LongerAgoThan(lastTime, timeout)) {
webClient.CancelAsync();
return false;
}
return !transferProgress.Completed;
});
return timer;
}