Ejemplo n.º 1
0
        private void ThreadFunction()
        {
            if (srcArgs.Surface.Scan0.MaySetAllowWrites)
            {
                srcArgs.Surface.Scan0.AllowWrites = false;
            }

            try
            {
                threadInitialized.Set();

                effect.SetRenderInfo(effectTokenCopy, dstArgs, srcArgs);

                RendererContext rc = new RendererContext(this);

                if (threadShouldStop)
                {
                    effect.SignalCancelRequest();
                }
                else if (tileCount > 0)
                {
                    // Render first tile by itself as an attempt at some extra thread safety guarding, and to support better quick-cancellation
                    rc.RenderNextTile(effectTokenCopy);
                }

                int          i;
                WaitCallback rcwc = new WaitCallback(rc.RendererThreadProc);

                for (i = 0; i < workerThreads; ++i)
                {
                    if (threadShouldStop)
                    {
                        effect.SignalCancelRequest();
                        break;
                    }

                    EffectConfigToken token;

                    if (effectTokenCopy == null)
                    {
                        token = null;
                    }
                    else
                    {
                        token = effectTokenCopy.CloneT();
                    }

                    threadPool.QueueUserWorkItem(rcwc, token);
                }

                threadPool.Drain();

                /*
                 * if (i == this.workerThreads)
                 * {
                 *  OnFinishedRendering();
                 * }
                 * */
            }

            catch (Exception ex)
            {
                exceptions.Add(ex);
            }

            finally
            {
                var threadPoolP = threadPool;

                if (!disposed && threadPoolP != null)
                {
                    try
                    {
                        threadPoolP.Drain();
                    }

                    catch (Exception)
                    {
                        // discard
                    }
                }

                OnFinishedRendering();

                var srcArgsP = srcArgs;

                if (srcArgsP != null)
                {
                    var surfaceP = srcArgsP.Surface;

                    if (surfaceP != null)
                    {
                        var scan0P = surfaceP.Scan0;

                        if (scan0P != null)
                        {
                            if (!disposed)
                            {
                                if (scan0P.MaySetAllowWrites)
                                {
                                    try
                                    {
                                        scan0P.AllowWrites = true;
                                    }

                                    catch (ObjectDisposedException)
                                    {
                                        // discard
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
 private void ThreadFunction()
 {
     if (this.srcArgs.Surface.Scan0.MaySetAllowWrites)
     {
         this.srcArgs.Surface.Scan0.AllowWrites = false;
     }
     try
     {
         this.threadInitialized.Set();
         this.effect.SetRenderInfo(this.effectTokenCopy, this.dstArgs, this.srcArgs);
         RendererContext context = new RendererContext(this);
         if (this.threadShouldStop)
         {
             this.effect.SignalCancelRequest();
         }
         else if (this.tileCount > 0)
         {
             context.RenderNextTile(this.effectTokenCopy);
         }
         WaitCallback rcwc = new WaitCallback(context.RenderNextTileProc);
         for (int i = 0; i < this.tileCount; i++)
         {
             if (this.threadShouldStop)
             {
                 this.effect.SignalCancelRequest();
                 break;
             }
             EffectConfigToken token = (this.effectTokenCopy == null) ? null : this.effectTokenCopy.CloneT <EffectConfigToken>();
             this.threadPool.Enqueue(() => rcwc(token));
         }
         this.threadPool.Join();
     }
     catch (Exception exception)
     {
         this.exceptions.Add(exception);
     }
     finally
     {
         EffectRendererWorkItemQueue threadPool = this.threadPool;
         if (!this.disposed && (threadPool != null))
         {
             try
             {
                 threadPool.Join();
             }
             catch (Exception)
             {
             }
         }
         this.OnFinishedRendering();
         RenderArgs srcArgs = this.srcArgs;
         if (srcArgs != null)
         {
             Surface surface = srcArgs.Surface;
             if (surface != null)
             {
                 MemoryBlock block = surface.Scan0;
                 if (((block != null) && !this.disposed) && block.MaySetAllowWrites)
                 {
                     try
                     {
                         block.AllowWrites = true;
                     }
                     catch (ObjectDisposedException)
                     {
                     }
                 }
             }
         }
     }
 }