Best way to implement a C# Windows Forms app. as a Singleton?

  • Thread starter Thread starter None
  • Start date Start date
N

None

I only want one instance of my C# Windows Forms app ever to run at the same
time.

I'm familiar with the Singleton pattern of course. What's the best way to
achieve that pattern with a Windows Forms app?
 
How about using Process.GetProcessesByName? Any drawbacks or gotchas to
that? I've tried it and it seems to work but I'm worried about unforeseen
complications or problems.
 
None said:
How about using Process.GetProcessesByName? Any drawbacks or gotchas to
that? I've tried it and it seems to work but I'm worried about unforeseen
complications or problems.

The most obvious gotcha is that two processes could have the same name
but be completely unrelated.

I seem to remember it also takes a while to complete, although I could
be wrong.

It just feels a bit messy to use names which already have one meaning
when you effectively want a system wide locking object, which is
exactly what a Mutex is.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top