c# - Gracefully closing multithreading application? -


I have an app that has two threads

The first (the main thread) that captures data and datatiles by using the data socket

The second includes the data tables in the database.

This application works fine, but when it stops, the main thread ends up reading the data and calls the abort method in the second thread, which can be included in the database And gets inconsistent data from it.

Currently I am using the following solution to overcome the "aborted during the entry"

Edit: Powerful answer I changed the code

< Pre> void MainThread () {while read ()) {// read data via socket {// wait mute x1 // update tables} {// release mute x1}} _isrunning = false ; _secondThread.Join (); } Void SecondThread () {while (_isrunning) {try {// wait Mute x1 // Insert tables using transactions in the database} Finally {// release right x1}}}

"Call aborted method" means to terminate the thread using the thread. .

There are several cleaner ways to do this with monitors that are crashing your app effectively.

Nevertheless, you should not get incompatible data in your DB when your app crashes, so you have a DB transaction, which has properties

Very important editing You said: You do not use transactions for performance reasons, and instead use mutes. It is wrong at some levels. First of all, transactions can accelerate some operations. For example, 10th in the table Try inserting the symbols, check it again within the transaction, the transaction version will be faster, secondly, what happens when / if your app crashes, do you corrupt your DB? What happens when many instances of your app are running? Or when you run a report against the query analyst against your DB?


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -