How can push be executed in multithreading without consuming cpu #1822
Unanswered
a645010545
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is your feature request related to a problem? Please describe.
public static class MessageMiddleware
{
private static readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1);
private static ConnectionFactory _factory;
private static IConnection _connection;
private static IChannel _channel;
private static string RabbitMQHostName = App.Configuration["RabbitMQConfig:HostName"];
private static string RabbitMQUserName = App.Configuration["RabbitMQConfig:UserName"];
private static string RabbitMQPassword = App.Configuration["RabbitMQConfig:Password"];
}
await MessageMiddleware.Init();
// 定义并发任务数量
const int concurrentTasks = 10000000;
// 创建任务数组
var tasks = new Task[concurrentTasks];
for (int i = 0; i < concurrentTasks; i++)
{
tasks[i] = Task.Run(async () =>
{
await MessageMiddleware.Push("remoteconfiguration", new { TokenId = "123456" });
});
}
// 等待所有任务完成
await Task.WhenAll(tasks);
Console.WriteLine("All push operations completed.");
Console.ReadLine();
Describe the solution you'd like
How can push be executed in multithreading without consuming cpu
Describe alternatives you've considered
No response
Additional context
No response
Beta Was this translation helpful? Give feedback.
All reactions