c# - I'm checking if my application is already running or not and it's saying running even if i stopped the application why? -



c# - I'm checking if my application is already running or not and it's saying running even if i stopped the application why? -

inside program.cs did:

using system; using system.collections.generic; using system.linq; using system.windows.forms; using system.diagnostics; using dannygeneral; namespace mws { static class programme { /// <summary> /// main entry point application. /// </summary> [stathread] static void main() { seek { if (isapplicationalreadyrunning() == true) { messagebox.show("the application running"); } else { application.enablevisualstyles(); application.setcompatibletextrenderingdefault(false); application.run(new form1()); } } grab (exception err) { logger.write("error " + err.tostring()); } } static bool isapplicationalreadyrunning() { string proc = process.getcurrentprocess().processname; process[] processes = process.getprocessesbyname(proc); if (processes.length > 1) { homecoming true; } else { homecoming false; } } } }

i used breakpoint , if closed programme in visual studio , seek run application 1 time again homecoming true , throw message application runnig.

in breakpoint saw variable proc contain: weather station.vshost

and noticed happen if open re-create of application in new visual studio window , application on location on hard disk , didn't run application not on of visual studios windows.

so why when have same application opened twice in visual studio , it's not running it's thinking running ? , if close sec visual studio still see in proc weather station.vshost time homecoming false.

edit

i see variable processes contain twice in index 0 , 1 weather station.vshost , if close sec visual studio contain one.

the question weather station.vshost ? , why count running application if application not running ? how can create checking improve if open more copies of application not think app running ?

the reason wanted open re-create of application sec 1 older , wanted see old things did.

i can alter this:

if (processes.length > 1)

and create > 10 illustration still don't understand weather station.vshost ? why it's running in memory ? , why it's considering running application ?

it seems trying create "single instance application". there several existing solutions published this. accepted way create utilize of mutex , see if held, here: what right way create single instance application?

additionally, appears feature built windows forms (which based on references in illustration source file, seem use). refer prevent application launch if running

c# .net winforms

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -