- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
可告知 Task.Delay
延迟的最长持续时间为 int.MaxValue
毫秒。创建将延迟超过该时间的 Task
的最简洁方法是什么?
// Fine.
await Task.Delay(TimeSpan.FromMilliseconds(int.MaxValue));
// ArgumentOutOfRangeException
await Task.Delay(TimeSpan.FromMilliseconds(int.MaxValue + 1L));
最佳答案
您无法使用单个 Task.Delay
实现这一点,因为它在内部使用仅接受 int 的 System.Threading.Timer
。
但是,您可以一个接一个地使用多个等待来做到这一点。这是最干净的方法:
static async Task Delay(long delay)
{
while (delay > 0)
{
var currentDelay = delay > int.MaxValue ? int.MaxValue : (int) delay;
await Task.Delay(currentDelay);
delay -= currentDelay;
}
}
关于c# - Task.Delay 超过 int.MaxValue 毫秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27995221/
asyncio.sleep() 的阻塞表亲,time.sleep() , 不能保证它会在请求的时间内休眠。 The actual suspension time may be less than th
在 C# 中,我有以下两个简单示例: [Test] public void TestWait() { var t = Task.Factory.StartNew(() => {
这是一个 linqpad 示例,展示了在短暂延迟后异步执行方法的两种方法。这两个例子似乎做了完全相同的事情。我通常会实现第一个版本(使用 Task.Delay.ContinueWith),但我也看到使
这是一个 linqpad 示例,展示了在短暂延迟后异步执行方法的两种方法。这两个例子似乎做了完全相同的事情。我通常会实现第一个版本(使用 Task.Delay.ContinueWith),但我也看到使
使用 jQuery,我逐渐将“go”类添加到 div div { tranform:translate(20px,20px); opacity:0;
期待: 当 audioplayer.play(atTime: 1) 被调用时,定时器重置为 0,音频播放器在第 1 秒播放 现实: 我试过 delay = 0.000000001, 1, 100000
我一直在阅读 .Net 4.5 中引入的 async/await 语法并对其有所了解。 我找到了简单的示例,其中 Task.Yield 是要走的路,而不是 Application.DoEvents。我
我需要在一个延迟很大的系统中调整PI(D)的增益。这是一个常见的温度 Controller ,但温度探头距离加热器较远。一些进一步的信息: 加热器响应上的任何变化,探头的响应都会延迟约10秒 温度以1
代码很短,但是很经典,单位是秒,就是未测试过服务器资源消耗怎么样: <% Function Delay(s)
为什么这会立即清空文本(忽略延迟)? $('#error_box_text').html('error text').delay(5000).html('') # jQuery 1.4 最佳答案 de
我有一个 $image,我 .fadeIn 和 .fadeOut,然后 .remove .fadeOut 完成。这是我的代码: $image .fadeIn() .fadeOut(func
我希望用户将鼠标悬停在对撞机(只是一个透明矩形)上超过 2 或 3 秒时能够看到描述菜单。我目前正在使用 javaFX 扩展。 我将程序设置为每当我将鼠标悬停在对撞机上时,它都会播放声音效果,但我希望
在我创建的几个 .HTA 脚本中,我需要 VBScript WScript.Sleep 命令,它只是等待几毫秒而不使用 CPU。当我浏览网页时,似乎我不是唯一一个在寻找这个的人: https://ww
我在 javaFX 中创建了一些节点。我需要为每个节点设置动画,以便使用 TranslateTransition 在 Pane 中的某个点到某个点之间进行转换。但我需要使每个节点使用不同的起点独立移动
我需要在用户开始触摸屏幕、移动手指然后结束触摸时执行一些操作。触摸开始工作正常,也可以移动,但触摸结束运行有 0.5-1 秒的延迟。下面有一段代码: -(id) init { if (s
我正在寻找有关 jQuery 的 .delay 函数的帮助。我的网站上有一个弹出表单,我想在 2-3 分钟内随机弹出该表单。我了解如何使用 Math.random(),但我不了解如何使用它生成 120
我无法获取一些 javascript 和 Jquery 来延迟适当的时间。我想更改一些文本,请等待 5 秒钟,然后弹出警报。 代码如下: $('#result').html("Record has p
我有以下 JavaScript 片段: $("#dashboard").addClass("standby").delay(3000).removeClass("standby"); $(".acti
我有以下 JavaScript 片段: $("#dashboard").addClass("standby").delay(3000).removeClass("standby"); $(".acti
我已经编写了一个简单的 jQuery 淡入淡出插件,但我无法让延迟正常工作。它将在第一个项目上起作用,但之后它会被忽略 jQuery (function ($) { $.fn.setupQuo
我是一名优秀的程序员,十分优秀!