Bloom.Program.GetRunningBloomProcessCount C# (CSharp) Method

GetRunningBloomProcessCount() public static method

Getting the count of running Bloom instances takes extra steps on Linux.
public static GetRunningBloomProcessCount ( ) : int
return int
        public static int GetRunningBloomProcessCount()
        {
            // The second test prevents counting the Bloom.vshost.exe process which Visual Studio and similar tools
            // create to speed up launching the program in debug mode. It's only useful for developers.
            var bloomProcessCount = Process.GetProcesses().Count(p => p.ProcessName.ToLowerInvariant().Contains("bloom")
                && !p.ProcessName.ToLowerInvariant().Contains("vshost"));

            // This is your count on Windows.
            if (SIL.PlatformUtilities.Platform.IsWindows)
                return bloomProcessCount;

            // On Linux, the process name is usually "mono-sgen" or something similar, but not all processes
            // with this name are instances of Bloom.
            var processes = Process.GetProcesses().Where(p => p.ProcessName.ToLowerInvariant().StartsWith("mono"));

            // DO NOT change this foreach loop into a LINQ expression. It takes longer to complete if you do.
            foreach (var p in processes)
            {
                bloomProcessCount += p.Modules.Cast<ProcessModule>().Any(m => m.ModuleName == "Bloom.exe") ? 1 : 0;
            }

            return bloomProcessCount;
        }