I have an application that should only be allowed to run one instance per user session. If the user clicks to launch the application again, I want to bring the one already to focus. I followed the steps in this tutorial WPF Single Instance Application
and the steps in this tutorial is :
Step 1: Add the file SingleInstance.cs to your project.
Step 2: Add a reference to your project: System.Runtime.Remoting.
Step 3: Have your application class implement ISingleInstanceApp (defined in SingleInstance.cs).
The only method in this interface is:
Hide Copy Code bool SignalExternalCommandLineArgs(IList args) This method is called when a second instance of your application tries to run. It has an args parameter which is the same as the command line arguments passed to the second instance.
Step 4: Define your own Main function that uses the single instance class.
Your App class should now be similar to this:
Hide Copy Code /// Step 5: Set new main entry point.
Select Project Properties –> Application and set “Startup object” to your App class name instead of “(Not Set)”.
Step 6: Cancel the default WPF main function.
Right click on App.xaml, Properties, set Build Action to "Page" instead of "Application Definition".
I stick at step 4 I don't know how to define my own Main function that uses the single instance class? anyone help me please, thanks