[Mono-list] single instance (mutex)

ingemar ingemar.pertl at kapsch.net
Thu Sep 1 06:52:23 EDT 2011


Hi all,

today I've solved the single instance issue with mono:

private static bool IsApplicationRunningOnMono(string processName)
        {
            var processFound = 0;

            Process[] monoProcesses;
            ProcessModuleCollection processModuleCollection;

            //find all processes called 'mono', that's necessary because our
app runs under the mono process!
            monoProcesses = Process.GetProcessesByName("mono");

            for (var i = 0; i <= monoProcesses.GetUpperBound(0); ++i)
            {
                processModuleCollection = monoProcesses[i].Modules;

                for (var j = 0; j < processModuleCollection.Count; ++j)
                {
                    if
(processModuleCollection[j].FileName.EndsWith(processName))
                    {
                        processFound++;
                    }
                }
            }

            //we don't find the current process, but if there is already
another one running, return true!
            return (processFound == 1);
        }

maybe that will help someone ;)

regards,
ingemar

--
View this message in context: http://mono.1490590.n4.nabble.com/single-instance-mutex-tp3765451p3783256.html
Sent from the Mono - General mailing list archive at Nabble.com.


More information about the Mono-list mailing list