Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • Does this answer your question? What is a good pattern for using a Global Mutex in C#? Commented Dec 17, 2020 at 15:12
  • Are you creating the mutex in a using statement? Commented Dec 17, 2020 at 15:14
  • 1
    Does this answer your question? Named Mutex with await Commented Dec 17, 2020 at 15:19
  • Have you tried the suggestion from this answer? It looks pretty nifty. They just create a named EventWaitHandle, and keep it alive for the duration of the app (a GC.KeepAlive(handle) at the end of the app may be needed). There is a comment warning for .NET Core not supporting this solution, but I just tested it on .NET 5 and it works fine. Commented Dec 17, 2020 at 18:19
  • @TheodorZoulias Yes, looks like it's much more convenient than mutex, thanks. Regarding .net core I believe it's about being non cross-platform. So when you use it under windows, it works, but if you try to run the same code for linux, for example, it will throw PlatformNotSupportedException. Commented Dec 17, 2020 at 22:54