C#
 Computer >> コンピューター >  >> プログラミング >> C#

C#のMutexクラスとは何ですか?


C#のMutexクラスは、プロセス間同期にも使用できる同期プリミティブです。

新しいMutexを作成する方法を見てみましょう。

private static Mutex m = new Mutex();

ここで、Mutexクラスの新しいインスタンスをブール値で初期化する方法を見てみましょう。

private static Mutex m = new Mutex(true);

次に、ブール値とMutexの名前を使用してMutexクラスの新しいインスタンスを初期化する方法を見てみましょう。

using System;
using System.Threading;

public class Demo {
   public static void Main() {
      Mutex mt = new Mutex(false, "NewMutex");
      Console.WriteLine("Waiting for the Mutex.");
      mt.WaitOne();
      Console.WriteLine("Owner of the mutex. " + "ENTER is to be pressed to release the mutexand          exit.");
      Console.ReadLine();
      mt.ReleaseMutex();
   }
}

出力

Waiting for the Mutex.
Owner of the mutex. ENTER is to be pressed to release the mutex and exit.

  1. C#のBitArrayクラスのCountプロパティとは何ですか?

    Countプロパティを使用して、BitArrayクラスの要素の数をカウントします。 まず、BitArrayクラスを設定しましょう- BitArray arr = new BitArray(10); 次に、以下に示すようにCountプロパティを使用します- 例 using System; using System.Collections; public class Demo {    public static void Main() {       BitArray arr = new BitArray(10);   &n

  2. C#のSortedListクラスのCapacityプロパティとは何ですか?

    SortedListクラスの容量プロパティには、SortedListの最大サイズがあります。 SortedListのデフォルトの容量は16です。 次のコードを実行して、C#でSortedListクラスのCapacityプロパティを実装してみてください- 例 using System; using System.Collections; namespace Demo {    class Program {       static void Main(string[] args) {