LoginSignup
2
2

More than 5 years have passed since last update.

Monoで名前付きMutexが期待通りに動作しない問題の解決方法

Posted at

ぐぐっても日本語の資料が見つからなかったので書いときます。

多重起動チェックのために次のような感じで書いたところ、Windowsでは多重起動した場合に期待通りif文中には入らないのに、Monoだと多重起動しても中に入ってしまった。

bool created_new_mutex;Mutex mutex = new Mutex(true, "hoge", out created_new_mutex);if (created_new_mutex) { /* … */ }```

どうも共有ハンドルがデフォルトで無効になっているのが原因らしい。
次のように環境変数 MONO_ENABLE_SHM=1 を設定したら解決した。

```Bash:
export MONO_ENABLE_SHM=1

参考

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2