About "Mutex" Learning and mutex Learning
Mutex)
A mutex lock is a mutex synchronization object, which means that only one thread can obtain it at a time.
The mutex lock can be used when a shared resource can be accessed by only one thread at a time.
When two or more threads need to access a shared resource at the same time, the system needs to use a synchronization mechanism to ensure that only one thread uses the resource at a time.
Mutex is a synchronization primitive that grants only one thread the exclusive access to shared resources. If a thread obtains the mutex, the second thread to obtain the mutex will be suspended until the first thread releases the mutex.
In my understanding, many people queue up for an ATM to withdraw money. They must wait until the first person gets the money, the second person can use it, and so on.
Code:
Public void AutomaticSubmitProcess (int MaxQueueStep, string System) {bool bCreateNew = false; Mutex mut = new Mutex (true, "name", out bCreateNew ); // use a Boolean value indicating whether the call thread should have the initial ownership of the mutex, // a string used as the name of the mutex, // a Boolean value indicating whether the call thread is granted the Initial ownership of the Mutex when the method returns to initialize a new instance of the Mutex class. If (bCreateNew = false) {// indicates that someone is taking money at the ATM. Please wait in line. Console. WriteLine ("Another Instance is running! "); Return;} // now you can get the money at the ATM, DataSet ds = Alb. getProcessOperationQueue (MaxQueueStep, "UBI"); if (ds. tables [0]. rows. count> 0) {// if the project is involved, no data modifications will be posted.} mut. releaseMutex (); // release Mutex once. Mut. Close (); mut. Dispose ();}
I used it for the first time, only explained my understanding, said wrong, and hoped to propose changes,