process - how to get PID of my app at runtime using C# -
process - how to get PID of my app at runtime using C# -
my app checks @ startup if other instance of same running already, if yes close other instances. tried using process.getprocessbyname("appname") function , store process appname in processes[] array. want find pid of current instance can close other instances of app (which have same name different pids). unable find after lot of googling. how can find pid of instance of app have created process.start("appname.exe") function called within appname.exe
ok, given problems other solution, see following
in order hook in between processes, need form of ipc. utilize simplicty of shared handles between eventwaithandles, create each programme hear cancellation flag.
public static eventwaithandle cancellationevent = new eventwaithandle( false, eventresetmode.autoreset, "myappcancel"); private object lockobject = new object();
and later...
task.run(() => { while(true) { cancellationevent.waitone(); lock(lockobject) if(!thisiscalling) // static bool prevent programme ending environment.exit(0); } }
and phone call cancellation so
lock(lockobject) { thisiscalling = true; cancellationevent.set(); thisiscalling = false; }
c# process pid instances
Comments
Post a Comment