////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public void Start()
        {
            m_startTicks = Environment.TickCount;

            m_lastOutputTimestamp = m_startTicks;

            m_exitMutex = new ManualResetEvent(false);

            m_process = new SyncProcess();

            m_process.StartInfo = StartInfo;

            m_process.OutputDataReceived += new DataReceivedEventHandler(ProcessStdout);

            m_process.ErrorDataReceived += new DataReceivedEventHandler(ProcessStderr);

            m_process.Exited += new EventHandler(ProcessExited);

            m_process.EnableRaisingEvents = true;

            LoggingUtils.Print(string.Format("[SyncRedirectProcess] Start: {0} (Args=\"{1}\" Pwd=\"{2}\")", m_process.StartInfo.FileName, m_process.StartInfo.Arguments, m_process.StartInfo.WorkingDirectory));

            m_process.Start();

            m_process.BeginOutputReadLine();

            m_process.BeginErrorReadLine();
        }
Exemplo n.º 2
0
        static void StartNewGame()
        {
            StartTasksProcess   = null;
            StartThreadsProcess = null;
            PrintResultEvent    = null;
            StartNewGameEvent   = null;

            var duration       = 10;
            var numberOfTreads = 10;
            var input          = "";

            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("********************* Welcome to Threads War!!! May the best win **************************");
            Console.WriteLine();

            //Number of Interactions
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("Enter number of interactions");
            Console.ForegroundColor = ConsoleColor.Yellow;
            input = Console.ReadLine();
            while (!int.TryParse(input, out duration))
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("Please enter correct number");
                Console.ForegroundColor = ConsoleColor.Yellow;
                input = Console.ReadLine();
            }

            //Number of Threads
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("Enter number of threads");
            Console.ForegroundColor = ConsoleColor.Yellow;
            input = Console.ReadLine();
            while (!int.TryParse(input, out numberOfTreads))
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("Please enter correct number");
                Console.ForegroundColor = ConsoleColor.Yellow;
                input = Console.ReadLine();
            }
            Console.ForegroundColor = ConsoleColor.White;

            var      dataArray      = GetRandomNumberArray(duration);
            IProcess syncProcess    = new SyncProcess(dataArray);
            IProcess tasksProcess   = new AsyncTaskProcess(dataArray);
            IProcess threadsProcess = new MultyThreadProcess(dataArray, numberOfTreads);

            StartTasksProcess             += new EventHandler(tasksProcess.Start);
            StartThreadsProcess           += new EventHandler(threadsProcess.Start);
            PrintResultEvent              += new EventHandler(() => PrintResult(syncProcess.ResultTime, tasksProcess.ResultTime, threadsProcess.ResultTime));
            StartNewGameEvent             += new EventHandler(StartNewGame);
            syncProcess.AfterFinishEvent   = StartTasksProcess;
            tasksProcess.AfterFinishEvent  = StartThreadsProcess;
            threadsProcess.TimeResultEvent = PrintResultEvent;
            //threadsProcess.StartNewGameEvent = StartNewGameEvent;
            syncProcess.Start();
        }
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    public void Start ()
    {
      m_startTicks = Environment.TickCount;

      m_lastOutputTimestamp = m_startTicks;

      m_exitMutex = new ManualResetEvent (false);

      m_process = new SyncProcess ();

      m_process.StartInfo = StartInfo;

      m_process.OutputDataReceived += new DataReceivedEventHandler (ProcessStdout);

      m_process.ErrorDataReceived += new DataReceivedEventHandler (ProcessStderr);

      m_process.Exited += new EventHandler (ProcessExited);

      m_process.EnableRaisingEvents = true;

      LoggingUtils.Print (string.Format ("[SyncRedirectProcess] Start: {0} (Args=\"{1}\" Pwd=\"{2}\")", m_process.StartInfo.FileName, m_process.StartInfo.Arguments, m_process.StartInfo.WorkingDirectory));

      m_process.Start ();

      m_process.BeginOutputReadLine ();

      m_process.BeginErrorReadLine ();
    }