c# - Block user from opening a form if other instance has this user -


my winform application must open specific form according logged users. @ login form, user authentication completed, user gives username-password. valid credentials inside .csv file. if user valid, login form hidden , form2 appears.

what want block user opens application (login form) , gives same username-password runs app. current solution add each process (instance) environment variable login's username this:

process proc = system.diagnostics.process.getcurrentprocess(); proc.startinfo.environmentvariables.add("g2guser",username); 

and when instance opens, checkes if user tries log in uses application. so, variable being checked:

list<process> processes =     system.diagnostics.process.getprocessesbyname(system.io.path.getfilenamewithoutextension(system.reflection.assembly.getentryassembly().location)).tolist(); foreach (process proc in processes) {    stringdictionary sd = proc.startinfo.environmentvariables;    if (!string.isnullorempty(sd["g2guser"]))       if (sd["g2guser"] == username) {; //block user} } 

the problem can see processes' list, environmentvariables not stored. can propose way approach?

i wouldn't recommend using environment variables.

given have arbitrary number of instances of application you'll need maintain form of tracking these users.

you communicate between applications making use of inter-process communication such named pipes see: example named pipes ipc read/write timeout

then communicating , forth between instances make decisions between them.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -