AutomatedTester.BrowserMob.Server.Start C# (CSharp) Method

Start() public method

public Start ( ) : string
return string
        public string Start()
        {
            _serverProcess = new Process
                                 {
                                     StartInfo = {FileName = _path}
                                 };
            if (_port != 0)
            {
                _serverProcess.StartInfo.Arguments = String.Format("--port={0}", _port);
            }
            
            try
            {
                if (IsListening())
                {
                    throw new Exception("BrowserMob Proxy Already running");
                    //var runningProcesses = Process.GetProcesses();
                    //// now check the modules of the process
                    //foreach (var process in runningProcesses)
                    //{
                    //    Debug.WriteLine(String.Format("Process: {0} ID: {1}", process.ProcessName, process.Id));
                    //    if (process.ProcessName.Equals("cmd"))
                    //    {
                    //        //Debug.WriteLine(process.MainModule.FileName);
                    //        foreach (ProcessModule module in process.Modules)
                    //        {
                    //            Debug.WriteLine(module.FileName);
                    //            Thread.Sleep(10);
                    //        }
                    //        Thread.Sleep(10);
                    //    }
                    //    //// now check the modules of the process
                    //    //foreach (ProcessModule module in process.Modules)
                    //    //{
                    //    //    Debug.WriteLine(module.FileName);
                    //    //    if (module.FileName.Contains("BrowserMob"))
                    //    //    {
                    //    //        process.Kill();
                    //    //    }
                    //    //}
                    //}
                    //Thread.Sleep(1000);
                }
                _serverProcess.Start();
                var count = 0;
                while (!IsListening())
                {
                    Thread.Sleep(1000);
                    count++;
                    if (count == 30)
                    {
                        throw new Exception("Can not connect to BrowserMob Proxy");
                    }
                }
            }
            catch(Exception e)
            {
                return("Exception: " + e.Message);
                _serverProcess.Dispose();
                _serverProcess = null;
            }
            return "Success from Starting Server";
        }