c# - how to call single instance class from App.xaml.cs -


i have application should allowed run 1 instance per user session. if user clicks launch application again, want bring 1 focus. followed steps in tutorial wpf single instance application

and steps in tutorial :

step 1: add file singleinstance.cs project.

step 2: add reference project: system.runtime.remoting.

step 3: have application class implement isingleinstanceapp (defined in singleinstance.cs).

the method in interface is:

hide copy code bool signalexternalcommandlineargs(ilist args) method called when second instance of application tries run. has args parameter same command line arguments passed second instance.

step 4: define own main function uses single instance class.

your app class should similar this:

hide copy code /// step 5: set new main entry point.

select project properties –> application , set “startup object” app class name instead of “(not set)”.

step 6: cancel default wpf main function.

right click on app.xaml, properties, set build action "page" instead of "application definition".

i stick @ step 4 don't know how define own main function uses single instance class? me please, thanks

okay easy add method app.xaml.cs file in app class:

[stathread]     public static void main(string[] args) {     if (singleinstance<app>.initializeasfirstinstance("myapp"))     {         var app = new app();         app.initializecomponent();         app.run();         // allow single instance code perform cleanup operations         singleinstance<app>.cleanup();     } } 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -