Example #1
0
        public void PortTest1()
        {
            // (Moritz Eberl) At least for my machine
            Assert.IsFalse(PortUtils.IsPortFree(1115));

            Assert.IsTrue(PortUtils.IsPortFree(11150));
        }
        public bool Start(bool waitOnStartup = true, TimeSpan?timeout = null)
        {
            _job = new Job();

            STARTUPINFO si = new STARTUPINFO();

            si.wShowWindow = 0;


            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();
            bool success           = Win32Process.CreateProcess(Executable, string.Format("{0} {1}", Executable, Parameter),
                                                                IntPtr.Zero, IntPtr.Zero, false,
                                                                ProcessCreationFlags.NORMAL_PRIORITY_CLASS |
                                                                ProcessCreationFlags.CREATE_NO_WINDOW |
                                                                ProcessCreationFlags.STARTF_USESTDHANDLES |
                                                                ProcessCreationFlags.CREATE_BREAKAWAY_FROM_JOB,
                                                                IntPtr.Zero, _workingDir.FullName, ref si, out pi);

            _job.AddProcess(pi.hProcess);
            _process = Process.GetProcessById((int)pi.dwProcessId);

            if (success && waitOnStartup)
            {
                double time = 0;
                if (timeout.HasValue)
                {
                    time = timeout.Value.TotalMilliseconds;
                }
                while (!_serverStartOccured)
                {
                    _serverStartOccured = !PortUtils.IsPortFree(Port);
                    if (!_serverStartOccured)
                    {
                        Thread.Sleep(10);
                        if (timeout.HasValue)
                        {
                            time -= 10;
                            if (time <= 0)
                            {
                                break;
                            }
                        }
                    }
                }
            }



            return(success);
        }