c# 如何在不停止主线程的情况下在 2 个函数调用之间暂停

标签 c# multithreading

c# 如何在不停止主线程的情况下在 2 个函数调用之间暂停

Foo();
Foo(); // i want this to run after 2 min without stopping main thread


Function Foo()
{
}

谢谢

最佳答案

尝试:

Task.Factory.StartNew(() => { foo(); })
    .ContinueWith(t => Thread.Sleep(2 * 60 * 1000))
    .ContinueWith(t => { Foo() });

关于c# 如何在不停止主线程的情况下在 2 个函数调用之间暂停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16086734/

相关文章:

java - 向主线程发送线程错误信号

c# - 将 WebClient 转换为 HttpClient

c# - 如何用充满 JPEG 图像的文件夹创建字节数组并将它们显示在 DataGridView 的列中?

c# - 如何从此数组中检索信息?

c# - Console.Clear() 闪烁

c++ - 多线程引擎窗口随机减速

c++ - 只写互斥锁

c# - Umbraco - 从多个下拉列表数据类型中获取预值并使用 Razor 创建无序列表

java - 按顺序并发运行 Runnable

c - 如何通过线程将数组作为返回值传递?