Пример #1
0
            protected override void Execute(Threading.ThreadPool owner)
            {
                try
                {
                    foreach (string file in System.IO.Directory.GetFiles(_Directory, "*", System.IO.SearchOption.TopDirectoryOnly))
                    {
                        try
                        {
                            if (!_Discovered.ContainsKey(file))
                            {
                                _Discovered[file] = DateTime.UtcNow;
                            }
                        }
                        catch { }
                    }
                }
                catch { }

                try
                {
                    foreach (string file in _Discovered.Keys.ToList())
                    {
                        if (!System.IO.File.Exists(file))
                        {
                            _Discovered.Remove(file);
                        }
                        else if ((DateTime.UtcNow - _Discovered[file]).TotalMinutes > 120)
                        {
                            System.IO.File.Delete(file);
                            _Discovered.Remove(file);
                        }
                    }
                }
                catch { }
            }
Пример #2
0
        public BackgroundEffectRenderer(Effect effect,
                                        EffectConfigToken effectToken,
                                        RenderArgs dstArgs,
                                        RenderArgs srcArgs,
                                        PdnRegion renderRegion,
                                        int tileCount,
                                        int workerThreads)
        {
            this.effect       = effect;
            this.effectToken  = effectToken;
            this.dstArgs      = dstArgs;
            this.srcArgs      = srcArgs;
            this.renderRegion = renderRegion;
            this.renderRegion.Intersect(dstArgs.Bounds);
            this.tileRegions = SliceUpRegion(renderRegion, tileCount, dstArgs.Bounds);

            this.tilePdnRegions = new PdnRegion[this.tileRegions.Length];
            for (int i = 0; i < this.tileRegions.Length; ++i)
            {
                PdnRegion pdnRegion = Utility.RectanglesToRegion(this.tileRegions[i]);
                this.tilePdnRegions[i] = pdnRegion;
            }

            this.tileCount     = tileCount;
            this.workerThreads = workerThreads;

            if ((effect.EffectDirectives & EffectDirectives.SingleThreaded) != 0)
            {
                this.workerThreads = 1;
            }

            this.threadPool = new Threading.ThreadPool(this.workerThreads, false);
        }
Пример #3
0
            protected override void Execute(Threading.ThreadPool owner)
            {
                try
                {
                    lock (_Cached)
                        if (_LastAttempt.ContainsKey(_File))
                        {
                            if ((DateTime.UtcNow - _LastAttempt[_File]).TotalSeconds < 10)
                            {
                                return;
                            }
                        }

                    VersionManager.Cache(_Cache, _File, _RenameSourceAssemblies);
                }
                catch (Exception ex)
                {
                    string s = ex.ToString();
                }
            }
        //traverse the tree on multiple threads...
        private void DrawItemsThread(DrawState state)
        {
            minBuffer[0] = boundsMin.X;
            minBuffer[1] = boundsMin.Y;
            minBuffer[2] = boundsMin.Z;

            maxBuffer[0] = boundsMax.X;
            maxBuffer[1] = boundsMax.Y;
            maxBuffer[2] = boundsMax.Z;

            Threading.ThreadPool pool = state.Application.ThreadPool;

            if (this.threads == null)
            {
                //create the threads.
                //must be a power-of-two number of thread tasks
                threadLevel = 0;
                int threadCount = 2;
                while (pool.ThreadCount >= threadCount)
                {
                    threadCount *= 2;
                    threadLevel++;
                }

                this.threads = new ThreadDrawer[threadCount];
                for (int i = 0; i < threadCount; i++)
                {
                    this.threads[i]      = new ThreadDrawer();
                    this.threads[i].axis = threadLevel % 3;
                }
            }

            Matrix world;

            state.GetWorldMatrix(out world);
            bool isIdentity = world == Matrix.Identity;

            for (int i = 0; i < this.threads.Length; i++)
            {
                this.threads[i].children      = this.allChildren;
                this.threads[i].nodes         = this.allNodes;
                this.threads[i].idenityMatrix = isIdentity;

                this.threads[i].cullTestInstanceCount = 0;
                this.threads[i].instanceCount         = 0;

                this.threads[i].treeIsOptimized = this.IsOptimizedState;
            }

            int index = 0;

            //traverse the tree, when getting to 'threadLevel' child depth, process on a thread
            DrawItemsThread(state, 0, 0, ref index, minBuffer, maxBuffer);

            //now wait for everything to finish...
            for (int i = 0; i < this.threads.Length; i++)
            {
                threads[i].callback.WaitForCompletion();
            }

            //iterate through the items to draw
            for (int t = 0; t < this.threads.Length; t++)
            {
                //some do not require cull tests
                if (this.IsOptimizedState)
                {
                    for (int i = 0; i < threads[t].instanceCount; i++)
                    {
                        ThreadDrawnInstance inst = threads[t].instances[i];

                        uint child = inst.firstChild;
                        child <<= ChildCountShift;

                        for (ushort c = 0; c < inst.childCount; c++)
                        {
                            IDraw item = allChildren[child++];
                            if (item != null)
                            {
                                item.Draw(state);
                            }
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < threads[t].instanceCount; i++)
                    {
                        ThreadDrawnInstance inst = threads[t].instances[i];

                        uint child = inst.firstChild;
                        child <<= ChildCountShift;

                        for (ushort c = 0; c < inst.childCount; c++)
                        {
                            allChildren[child++].Draw(state);
                        }
                    }
                }

                //some do.
                for (int i = 0; i < threads[t].cullTestInstanceCount; i++)
                {
                    ThreadDrawnInstance inst = threads[t].cullTestInstances[i];

                    uint child = inst.firstChild;
                    child <<= ChildCountShift;

                    for (ushort c = 0; c < inst.childCount; c++)
                    {
                        if (allChildren[child].CullTest(state))
                        {
                            allChildren[child].Draw(state);
                        }
                        child++;
                    }
                }
            }
        }