他们好像和我一样,这两行代码有区别吗?
new Task(myMethod).RunSynchronously();
// and
Task.Run(() => myMethod());
最佳答案
如评论中所述,您可以在文档中看到差异:
Task.Run(() => myMethod());
Queues the specified work to run on the thread pool and returns a Task object that represents that work.
新任务(myMethod).RunSynchronously();
Runs the Task synchronously on the current TaskScheduler.
因此,它们不再相同。
关于c# - 非等待的 Task.Run 和 Task.RunSynchronously 之间有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47825486/