.NET分派器,用于.NET Core?

编程入门 行业动态 更新时间:2024-10-18 12:23:32
本文介绍了.NET分派器,用于.NET Core?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

.NET Core是否存在类似 Dispatcher 的东西?

Does something like Dispatcher exist for .NET Core?

我需要在.NET中创建一个线程核心,并能够发送要在线程上调用的动作。另外,我希望能够使用 TaskScheduler 可以用于 async / await 的东西。

I need to create a thread in .NET Core, and be able to send actions to be invoked on the thread. Also, I'd like to be able to use a TaskScheduler that can be used for async/await stuff.

这是否存在?

推荐答案

它不是内置的,但是我的 AsyncContext 和 AsyncContextThread 类型在满足您需求的库中可用。

It's not built-in, but my AsyncContext and AsyncContextThread types are available in a library that would fit your need.

AsyncContext 接管当前线程:

AsyncContext.Run(async () => { ... // any awaits in here resume on the same thread. }); // `Run` blocks until all async work is done.

AsyncContextThread 是具有自己的独立线程 AsyncContext :

AsyncContextThread is a separate thread with its own AsyncContext:

using (var thread = new AsyncContextThread()) { // Queue work to the thread. thread.Factory.Run(async () => { ... // any awaits in here resume on the same thread. }); await thread.JoinAsync(); // or `thread.Join();` }

AsyncContext 提供 SynchronizationContext 以及 TaskScheduler / TaskFactory 。

更多推荐

.NET分派器,用于.NET Core?

本文发布于:2023-11-15 21:31:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1598128.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:NET   Core

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!