This article is a mirror article of machine translation, please click here to jump to the original article.

View: 60677|Reply: 4

[Source] .NET/C# is based on the BlockingCollection background task queue

[Copy link]
Posted on 2021-1-23 11:53:25 | | | |
c# encapsulates a universal QueueHelper queue
https://www.itsvse.com/thread-5029-1-1.html
.NET/C# implements simple logging based on BlockingCollection
https://www.itsvse.com/thread-9512-1-1.html
Scenario: When performing certain operations, there is no need to return any message, and the function that can be processed in the background can be placed in any part of the background to be executed. For example: sending emails, writing logs, etc.

I have previously written about task queues based on ConcurrentQueue and Thread, but this article uses BlockingCollection to achieve it better.

The QueueBlockingCollection code is as follows:

For example, let's implement a background task that sends a message that inherits the QueueBlockingCollection abstract class, as follows:

The call method is as follows:


Simple console background output string, the code is as follows:

The renderings are as follows:



(End)




Previous:ASP.NET Core receives POST JSON parameters that cannot be serialized into objects
Next:.net/c# enables 100% CPU processor usage
 Landlord| Posted on 2021-6-11 15:05:55 |
The code is a bit problematic, the latest code is as follows:


Posted on 2023-4-10 17:35:55 |
I'm going to take a look
Posted on 2023-5-8 09:58:53 |
Consumers can also get messages through codes like this:

 Landlord| Posted on 2023-5-8 22:13:24 |
.NET Core high-performance queue Channels is used
https://www.itsvse.com/thread-10584-1-1.html
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com