Skip to content

Commit b917ced

Browse files
authored
Create README.md
1 parent 1d18d89 commit b917ced

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
```

0 commit comments

Comments
 (0)