c# - Instance aware application pass arguments window forms app -


i want build c# app - should act skype in way create link in web page , executes "callto" action app passing arguments. want app in taskbar only.

so fire app first time , next time click link execute again on first application.

<a href="myapp:12345">click me</a> 

i'll set windows registry respond accordingly should fire app arguments

e.g. myapp.exe /12345

i can make app work every time click link new instance, how pass arguments running application?

inspired on this preventing second instance , this namedpipeserver

static void main(string[] args) {      string appguid = ((guidattribute)assembly.getexecutingassembly().getcustomattributes(typeof(guidattribute), false).getvalue(0)).value.tostring();      // unique id global mutex - global prefix means global machine     string mutexid = string.format("global\\{{{0}}}", appguid);      using (var mutex = new mutex(false, mutexid))     {          var hashandle = false;         try         {             try             {                 hashandle = mutex.waitone(5000, false);             }             catch (abandonedmutexexception)             {                 hashandle = true;             }               if (hashandle)             {                 // main app                 application.enablevisualstyles();                 application.setcompatibletextrenderingdefault(false);                 form1 frm = new form1();                  handleargs(args,frm); // handle first start args                  server(appguid, frm); // handle next clients                  application.run(frm);             }             else             {                 //any next client..                 var cli = new namedpipeclientstream(appguid);                 // connect first app                 cli.connect();                 // serialiaze args , send on                 var bf = new binaryformatter();                 bf.serialize(cli, args);  // commandline args on line                 cli.flush();                 cli.close();                 // done             }         }                 {             if (hashandle)                 mutex.releasemutex();         }     } }  // usefull stuff commandline args static void handleargs(string[] args, form1 frm) {     foreach (var s in args)     {         // append args textbox         frm.textbox1.text += s;         frm.textbox1.text += environment.newline;     } }  // server runs async static void server(string appguid, form1 frm) {     var srv = new namedpipeserverstream(appguid, pipedirection.inout, 5, pipetransmissionmode.byte, pipeoptions.asynchronous);      srv.beginwaitforconnection(state =>     {         namedpipeserverstream nps = (namedpipeserverstream)state.asyncstate;         nps.endwaitforconnection(state);          var bf = new binaryformatter();         string[] args = (string[])bf.deserialize(nps);          // don't forget call on ui thread         frm.invoke(new methodinvoker(() => { handleargs(args, frm); }));          nps.disconnect();          server(appguid, frm); // restart server     }, srv); } 

Comments