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

View: 57872|Reply: 7

[Source] c# encapsulates a universal QueueHelper queue

[Copy link]
Posted on 8/29/2018 10:39:11 AM | | | |
In daily development, we may use queues, which are a storage structure that can achieve "first-in, first-out".

Application scenarios: write logs, send emails, etc

If we need to record the interface log of each user requesting our data, we don't need to write a log every time the user requests it, we can put the log content in the queue and let other threads execute it, so as not to affect the efficiency of the application.

Another advantage is that adding data to the queue in the case of concurrency, using a single thread to execute the data of the queue can avoid many exceptions, if concurrency (multi-threaded), access to the same physical file will cause exceptions. (subject to availability)

Queue universal approach:

This is an abstract class, and you need to inherit this abstraction class and implement the Execute abstraction method. Because I don't know what type of data you want to process, generics are used here, that is, Entity is of string type, method parameters are of string type, and the data you are processing is string type data.

ConcurrentQueue thread-safe queue ensures that there will be no exceptions in a multi-threaded environment.

ManualResetEvent to control the thread's signal,In the past, we checked the queue for data every few seconds or minutesNow, we add the data to the queue and only need to pass a signal!

Use:

(End)




Previous:Setup Project installation package production process I want to copy the primary output file question
Next:The issue of redis Chinese cannot be displayed properly
 Landlord| Posted on 5/24/2019 10:13:59 AM |
Recommend a framework:

asp.net background task hangfire framework tutorial
https://www.itsvse.com/thread-7611-1-1.html
(Source: Architect_Programmer)
Posted on 9/10/2019 10:26:26 AM |
Why is the Execute method in the Test class not executed when I execute it?
 Landlord| Posted on 9/10/2019 9:52:44 PM |
hano7758 Posted on 2019-9-10 10:26
Why is the Execute method in the Test class not executed when I execute it?

Can you post your code?
 Landlord| Posted on 1/23/2021 11:53:46 AM |
.NET/C# is based on the BlockingCollection background task queue
https://www.itsvse.com/thread-9528-1-1.html

Posted on 7/26/2021 2:09:53 PM |
How can you see the code
Posted on 9/26/2022 10:20:08 PM |
I need to learn how to use it
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