예제 #1
0
        /// <summary>
        /// Starts the server in an external process, or in an internal background-thread if it is not already running.
        /// </summary>
        /// <param name="RunExternal">
        /// If true, an external process is used.
        /// </param>
        /// <returns>
        /// - true: the server was just started
        /// - false: the server is already running
        /// </returns>
        public static bool StartIfNotRunning(bool RunExternal = true, string BatchInstructionDir = null)
        {
            BatchInstructionDir = BatchInstructionDir != null ? BatchInstructionDir : Configuration.GetDefaultBatchInstructionDir();

            if (ServerExternal != null && ServerExternal.HasExited)
            {
                ServerExternal.Dispose();
                ServerExternal = null;
            }

            if (ServerInternal != null && !ServerInternal.IsAlive)
            {
                ServerInternal = null;
            }

            if (ServerExternal != null || ServerInternal != null || GetIsRunning(BatchInstructionDir))
            {
                Console.WriteLine("Mini batch processor is already running.");
                return(false);
            }
            Random r = new Random();

            r.Next(100, 5000);
            if (GetIsRunning(BatchInstructionDir))
            {
                Console.WriteLine("Mini batch processor is already running.");
                return(false);
            }

            if (RunExternal)
            {
                Console.WriteLine("Starting mini batch processor in external process...");

                ProcessStartInfo psi = new ProcessStartInfo();
                psi.FileName = typeof(Server).Assembly.Location;

                Process p = Process.Start(psi);

                Console.WriteLine("Started mini batch processor on local machine, process id is " + p.Id + ".");

                ServerExternal           = p;
                MiniBatchThreadIsMyChild = true;
            }
            else
            {
                Console.WriteLine("Starting mini batch processor in background thread...");

                Thread ServerThread = (new Thread(delegate() {
                    var s = new Server(null);
                    s._Main(new string[0]);
                }));
                ServerThread.Start();

                ServerInternal           = ServerThread;
                MiniBatchThreadIsMyChild = true;
            }
            return(true);
        }
예제 #2
0
파일: Server.cs 프로젝트: xj361685640/BoSSS
        /// <summary>
        /// Starts the server in an external process, or in an internal background-thread if it is not already running.
        /// </summary>
        /// <param name="RunExternal">
        /// If true, an external process is used.
        /// </param>
        public static void StartIfNotRunning(bool RunExternal = true)
        {
            if (ServerExternal != null && ServerExternal.HasExited)
            {
                ServerExternal.Dispose();
                ServerExternal = null;
            }

            if (ServerInternal != null && !ServerInternal.IsAlive)
            {
                ServerInternal = null;
            }

            if (ServerExternal != null || ServerInternal != null || IsRunning)
            {
                Console.WriteLine("Mini batch processor is already running.");
                return;
            }
            Random r = new Random();

            r.Next(100, 5000);
            if (IsRunning)
            {
                Console.WriteLine("Mini batch processor is already running.");
                return;
            }

            if (RunExternal)
            {
                Console.WriteLine("Starting mini batch processor in external process...");

                ProcessStartInfo psi = new ProcessStartInfo();
                psi.FileName = typeof(Server).Assembly.Location;

                Process p = Process.Start(psi);

                Console.WriteLine("Started mini batch processor on local machine, process id is " + p.Id + ".");

                ServerExternal = p;
            }
            else
            {
                Console.WriteLine("Starting mini batch processor in background thread...");

                Thread ServerThread = (new Thread(delegate() {
                    Main(new string[0]);
                }));
                ServerThread.Start();

                ServerInternal = ServerThread;
            }
        }