File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # SingleInstanceCore
2+ Single instance application - For WPF on .NET Core
3+ # Usage
4+ The App class (on App.xaml.cs) should inherit ISingleInstance and implement OnInstanceInvoked method:
5+ ``` csharp
6+ public partial class App : Application , ISingleInstance
7+ {
8+ public void OnInstanceInvoked (string [] args )
9+ {
10+ // What to do with the args another instance has sent
11+ }
12+ ...
13+ }
14+ ```
15+ The initialization of the instance should be done on application startup or main window's startup
16+ Cleanup method should be called on the exit point of the application.
17+ ``` csharp
18+
19+ private void Application_Startup (object sender , StartupEventArgs e )
20+ {
21+ bool isFirstInstance = SingleInstance <App >.InitializeAsFirstInstance (" soheilkd_EPlayerIPC" ))
22+ if (! isFirstInstance )
23+ {
24+ // If it's not the first instance, arguments are automatically passed to the first instance
25+ // OnInstanceInvoked will be raised on the first instance
26+ // You may shut down the current instance
27+ Current .Shutdown ();
28+ }
29+ }
30+
31+ private void Application_Exit (object sender , ExitEventArgs e )
32+ {
33+ // Do not forget to cleanup
34+ SingleInstance <App >.Cleanup ();
35+ }
36+ ```
You can’t perform that action at this time.
0 commit comments