Catatan

Tunjukkan catatan dari Februari, 2024

C# Queue with Concurrent Multithreading

Imej
Refer this link :  https://chat.openai.com/share/38a022ef-4af5-4913-afd1-c39c0aa366df The idea - C# queue with multithread So here is the scenario, 1. All TCP message is keep in queue before process and dequeue. 2. The background worker read the queue and distribute the process to multiple thread. 3. Each thread will lock the SQL update statement to prevent deadlock. 4. If one of thread need to access the lock SQL, this thread need to wait first until the thread that lock the SQL release the lock. 5. After thread done process the data, background worker will assign another message to the thread to process. Suggestion from Chatgpt This code demonstrates a basic setup for processing TCP messages from a queue using multiple threads in C#. It uses a ConcurrentQueue to store the TCP messages and distributes the processing of these messages across multiple threads. The SQL updates are locked using a lock statement to prevent multiple threads from accessing the SQL update simultaneously and c