示例#1
0
文件: OpCore.cs 项目: nandub/DeOps
        AsyncCoreFunction RunInCoreThread(Delegate method, params object[] args)
        {
            AsyncCoreFunction function = new AsyncCoreFunction(method, args);

            lock (CoreMessages)
                if (CoreMessages.Count < 100)
                {
                    CoreMessages.Enqueue(function);
                }

            ProcessEvent.Set();

            return(function);
        }
示例#2
0
文件: OpCore.cs 项目: swax/DeOps
        AsyncCoreFunction RunInCoreThread(Delegate method, params object[] args)
        {
            AsyncCoreFunction function = new AsyncCoreFunction(method, args);

            lock (CoreMessages)
                if (CoreMessages.Count < 100)
                    CoreMessages.Enqueue(function);

            ProcessEvent.Set();

            return function;
        }
示例#3
0
文件: OpCore.cs 项目: nandub/DeOps
        void RunCore()
        {
            // timer / network events are brought into this thread so that locking between network/core/components is minimized
            // so only place we need to be real careful is at the core/gui interface

            bool keepGoing = false;


            while (CoreRunning && Context.ContextThread.IsAlive)
            {
                if (!keepGoing)
                {
                    ProcessEvent.WaitOne(1000, false); // if context crashes this will release us
                }
                keepGoing = false;

                try
                {
                    AsyncCoreFunction function = null;

                    // process invoked functions, dequeue quickly to continue processing
                    lock (CoreMessages)
                        if (CoreMessages.Count > 0)
                        {
                            function = CoreMessages.Dequeue();
                        }

                    if (function != null)
                    {
                        function.Result    = function.Method.DynamicInvoke(function.Args);
                        function.Completed = true;
                        function.Processed.Set();

                        keepGoing = true;
                    }

                    // run timer, in packet loop so that if we're getting unbelievably flooded timer
                    // can still run and clear out component maps
                    if (RunTimer)
                    {
                        RunTimer = false;

                        SecondTimer();
                    }


                    // get the next packet off the queue without blocking the recv process
                    lock (Network.IncomingPackets)
                        if (Network.IncomingPackets.Count > 0)
                        {
                            Network.ReceivePacket(Network.IncomingPackets.Dequeue());

                            keepGoing = true;
                        }
                }
                catch (Exception ex)
                {
                    Network.UpdateLog("Core Thread", ex.Message + "\n" + ex.StackTrace);
                }
            }
        }