Пример #1
0
        public void RunOnThread(BrowserHost host, PipeServer server)
        {
            SetForcedFps(true, 16);

            try
            {
                Logr.Log("Started task runner.");

                while (KeepAlive)
                {
                    lock (_taskList)
                    {
                        while (_taskList.Count > 0)
                        {
                            var nextTask = _taskList.Dequeue();

                            try
                            {
                                if (_enableForcedFps && (nextTask is SendFrameTask || nextTask is RepaintFrameTask))
                                {
                                    _idleTicks = 0;
                                }

                                nextTask.Run(host, server);
                            }
                            catch (Exception ex)
                            {
                                Logr.Log("Exception while executing internal task:", ex.Message, ex);
                            }
                        }

                        if (_enableForcedFps && _idleTicks++ >= _autoRepaintTicks)
                        {
                            host.Repaint();
                        }
                    }

                    Thread.Sleep(1); // we need to run more than 30 times per second for frame transfers
                }

                Logr.Log("Task runner shutting down.");
            }
            catch (ThreadInterruptedException) { }
            catch (ThreadAbortException) { }
        }
        public static void Main(string[] args)
        {
            // Read args
            string pipeName = args.Length > 0 ? args[0] : "";

            if (String.IsNullOrWhiteSpace(pipeName))
            {
                pipeName = "default";
            }

            // Environment prep
            Console.Title = String.Format("CEF Ingame Browser [{0}]", pipeName);

            Environment.ExitCode = 1;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            Logr.Log("Starting CefUnityServer at", DateTime.Now);

            // Initialize core components
            Program.taskRunner            = new TaskRunner();
            Program.pipeServer            = new PipeServer(pipeName, taskRunner);
            Program.browserHost           = new BrowserHost(taskRunner);
            Program.browserHost.starturl  = args.Length > 1 ? args[1] : "google.com";
            Program.browserHost.startsize = args.Length > 2 ? args[2] : "1024x768";
            // Initialize CEF browser and wait for it to be ready
            Logr.Log("Waiting for Chromium to be ready.");

            Program.browserHost.Start();

            Logr.Log("Browser started and initialized.");

            // Begin named pipe server for data comm
            pipeServer.StartAsNewTask();

            // Begin task runner
            Program.taskRunner.RunOnThread(browserHost, pipeServer);

            // Clean shutdown
            Logr.Log("Nothing left to do on main thread. (Clean shutdown)");
            Environment.ExitCode = 0;

            // Wait before shutdown so msg is visible in console & everything shuts down clean
            Thread.Sleep(1000);
        }
Пример #3
0
        public void RunOnThread(BrowserHost host, PipeServer server)
        {
            this.host   = host;
            this.server = server;

            try
            {
                Logr.Log("Started task runner.");

                while (KeepAlive)
                {
                    lock (taskList)
                    {
                        while (taskList.Count > 0)
                        {
                            var nextTask = taskList[0];
                            taskList.RemoveAt(0);

                            try
                            {
                                nextTask.Run(host, server);
                            }
                            catch (Exception ex)
                            {
                                Logr.Log("Exception while executing internal task:", ex.Message, ex);
                            }
                        }
                    }

                    Thread.Sleep(1); // we need to run more than 30 times per second for frame transfers
                }

                Logr.Log("Task runner shutting down.");
            }
            catch (ThreadInterruptedException) { }
            catch (ThreadAbortException) { }
        }