In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to use mutex Mutex in C# multithreading". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use the mutex Mutex in C# multithreading.
I. brief introduction
The outstanding feature of Mutex is that it can access resources exclusively across application domain boundaries, that is, it can be used to synchronize threads in different processes, of course, at the expense of more system resources.
Two main commonly used methods:
Public virtual bool WaitOne () blocks the current thread until the current System.Threading.WaitHandle receives a signal to acquire the mutex.
Public void ReleaseMutex () releases System.Threading.Mutex once.
II. Code
Case 1:
Class Program {private static Mutex mutex = new Mutex (); static void Main (string [] args) {Thread [] thread = new Thread [3]; for (int I = 0; I < 3; iTunes +) {thread [I] = new Thread (ThreadMethod1) / / method reference thread [I] .Name = "Thread-" + (iReader 1). ToString ();} for (int I = 0; I < 3; iThread +) {thread [I] .start ();} Console.ReadKey () } public static void ThreadMethod1 (object val) {mutex.WaitOne (); / / acquire lock for (int I = 1; I
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.