Are you running .NET 1.1 or 2.0?
If you are running 1.1 or before, then you will have to use a mutex to
limit access. Basically, you will create a unique name for your mutex (the
assembly qualified name of the type that has the entry point to your program
will do nicely).
Then, before you call the static Run method with the Application class,
you would try and get ownership with this Mutex. If you can, then you run
the app, if you can't, you simply exit out.
In .NET 2.0, it is significantly easier. All you have to do is create a
class that derives from WindowsFormsApplicationBase in the
Microsoft.VisualBasic namespace. In the constructor, you set the
IsSingleInstance property to true, and then set the MainForm property to an
instance of your form.
Then, in your entry point, call the Run method on an instance of your
derived class, and viola, single instance semantics.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
"Jeffery Tyree" <Jeffer...@yahoo.com> wrote in message
news:Ot2zE12...@TK2MSFTNGP15.phx.gbl...
1) Use some form of mutex flag such as a local file that is opened for
exclusive read. Then the next instance would try to open that file and get
an error so you know some other instance is working.
2) Use the Process.GetProcessesByName and close the app if more than one
instance is returned. Have never done this but I would think it would work.
"Jeffery Tyree" <Jeffer...@yahoo.com> wrote in message
news:Ot2zE12...@TK2MSFTNGP15.phx.gbl...
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
"Peter Rilling" <pe...@nospam.rilling.net> wrote in message
news:eV0FC829...@tk2msftngp13.phx.gbl...
I never thought I would say it, but VB seems to have some constructs that C#
should have.
"Nicholas Paldino [.NET/C# MVP]" <m...@spam.guard.caspershouse.com> wrote in
message news:u0wXc729...@TK2MSFTNGP11.phx.gbl...
namespace YourRootNamespace
{
namespace My
{
internal partial class MyApplication :
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
{
[global::System.Diagnostics.DebuggerStepThrough()]
public MyApplication() :
base(Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows)
{
this.IsSingleInstance = false;
this.EnableVisualStyles = true;
this.SaveMySettingsOnExit = true;
this.ShutdownStyle =
Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses;
}
[global::System.Diagnostics.DebuggerStepThrough()]
protected override void OnCreateMainForm()
{
this.MainForm = new global::YourRootNamespace.YourForm();
}
[STAThread]
static void Main(string[] args)
{
MyApplication MyApp = new MyApplication();
MyApp.Run(args);
}
}
}
} //end of root namespace
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant C++: C# to C++ Converter
Instant J#: VB.NET to J# Converter
I would expect the WPF to have this baked-in though. It won't matter at
that point.
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
"Peter Rilling" <pe...@nospam.rilling.net> wrote in message
news:eQB57F39...@tk2msftngp13.phx.gbl...
-Jeff