Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BackgroundTask"/> class.
        /// </summary>
        /// <param name="theDelegate">The delegate.</param>
        public BackgroundTask(Func <object> theDelegate)
        {
            worker = new BackgroundWorker
            {
                WorkerSupportsCancellation = true,
                WorkerReportsProgress      = true
            };

            context = new BackgroundContext(worker);

            worker.DoWork += (s, e) => {
                Log.Info("Starting background task.");

                CurrentContext = context;
                Starting(this, EventArgs.Empty);

                e.Result = theDelegate();
                e.Cancel = cancellationPending;

                CurrentContext = null;
                Log.Info("Completed background task.");
            };

            worker.ProgressChanged += (s, e) => {
                ProgressChanged(this, new ProgressChangedEventArgs(e.ProgressPercentage, e.UserState));
            };

            worker.RunWorkerCompleted += (s, e) => {
                Completed(this, new RunWorkerCompletedEventArgs(e.Error != null || e.Cancelled ? null : e.Result, e.Error, e.Cancelled));
            };
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BackgroundTask"/> class.
        /// </summary>
        /// <param name="theDelegate">The delegate.</param>
        public BackgroundTask(Func<object> theDelegate)
        {
            worker = new BackgroundWorker
            {
                WorkerSupportsCancellation = true,
                WorkerReportsProgress = true
            };

            context = new BackgroundContext(worker);

            worker.DoWork += (s, e) =>{
                Log.Info("Starting background task.");

                CurrentContext = context;
                Starting(this, EventArgs.Empty);

                e.Result = theDelegate();
                e.Cancel = cancellationPending;

                CurrentContext = null;
                Log.Info("Completed background task.");
            };

            worker.ProgressChanged += (s, e) =>{
                ProgressChanged(this, new ProgressChangedEventArgs(e.ProgressPercentage, e.UserState));
            };

            worker.RunWorkerCompleted += (s, e) =>{
                Completed(this, new RunWorkerCompletedEventArgs(e.Error != null || e.Cancelled ? null : e.Result, e.Error, e.Cancelled));
            };
        }
Esempio n. 3
0
    public async Task ParseAsync(XmlReader reader, IParsingContext parsingContext, IParentParsingContext parentParsingContext)
    {
        var context = new BackgroundContext();
        await elementParser.ParseAsync(reader, parsingContext, context, Settings);

        if (!string.IsNullOrWhiteSpace(context.ParsedText))
        {
            var state = new BackgroundState(context.ParsedText, BackgroundType.Image, BackgroundPosition.Left);
            var block = parsingContext.BlockFactory.Create(
                new BackgroundNode(state, null),
                new ScrollNode(null)
                );
            parentParsingContext.AddNode(new BlockNode(block, context.When));
            parsingContext.RegisterDismissNode(DismissNode);
            return;
        }

        if (context.Nodes.Count == 0)
        {
            parsingContext.LogError(reader, "Nome de imagem ou elemento filho era esperado.");
            return;
        }

        {
            var block = parsingContext.BlockFactory.Create(context.Nodes);
            parentParsingContext.AddNode(new BlockNode(block, context.When));
            parsingContext.RegisterDismissNode(DismissNode);
        }
    }
Esempio n. 4
0
        public void Dispose()
        {
            BackgroundContext.Dispose();

            if (_copyFramebufferHandle != 0)
            {
                GL.DeleteFramebuffer(_copyFramebufferHandle);

                _copyFramebufferHandle = 0;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BackgroundTask"/> class.
        /// </summary>
        /// <param name="threadPool">The thread pool.</param>
        /// <param name="theDelegate">The delegate to execute.</param>
        public BackgroundTask(IThreadPool threadPool, Func<object> theDelegate)
        {
            if(threadPool == null)
                throw new ArgumentNullException("threadPool");

            if(theDelegate == null)
                throw new ArgumentNullException("theDelegate");

            _threadPool = threadPool;
            _theDelegate = theDelegate;
            _context = new BackgroundContext(this);
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BackgroundTask"/> class.
        /// </summary>
        /// <param name="threadPool">The thread pool.</param>
        /// <param name="theDelegate">The delegate to execute.</param>
        public BackgroundTask(IThreadPool threadPool, Func <object> theDelegate)
        {
            if (threadPool == null)
            {
                throw new ArgumentNullException("threadPool");
            }

            if (theDelegate == null)
            {
                throw new ArgumentNullException("theDelegate");
            }

            _threadPool  = threadPool;
            _theDelegate = theDelegate;
            _context     = new BackgroundContext(this);
        }
Esempio n. 7
0
        public void Dispose()
        {
            BackgroundContext.Dispose();

            if (_copyFramebufferHandle != 0)
            {
                GL.DeleteFramebuffer(_copyFramebufferHandle);

                _copyFramebufferHandle = 0;
            }

            if (_stagingFrameBuffer != 0)
            {
                GL.DeleteTextures(_stagingTextures.Length, _stagingTextures);
                GL.DeleteFramebuffer(_stagingFrameBuffer);
                _stagingFrameBuffer = 0;
                _stagingTextures    = null;
            }
        }