How to implement singleton pattern in notifier project c#? -


first of all, requirement. created project notifier in tray. after execution created many instances in tray , gradually decreases one. decided use singleton ensure single instance created.

i found following code showing how create singleton don't know how implement in project , 1 instance notification tray?

public class singleton {     private singleton()     {         // prevent outside instantiation     }      private static readonly singleton _singleton = new singleton();      public static singleton getsingleton()     {         return _singleton;     } } 

you can use in entry point as

static readonly mutex singleton = new mutex(true, "appname");     static void main()             {                 if (!singleton.waitone(timespan.zero, true))                 {                    messagebox.show("another instance running.");                    return;                 }             } 

Comments