Exemple #1
0
        public AutoRenderPolicy(IPlot plot)
            : base(plot)
        {
            task = Task.Factory.StartNew(async() =>
            {
                try
                {
                    var channel = Channel.CreateUnbounded <int>(new UnboundedChannelOptions
                    {
                        SingleReader = true,
                        SingleWriter = true
                    });

                    var reader = channel.Reader;
                    writer     = channel.Writer;

                    var token = cancellationTokenSource.Token;

                    while (await reader.WaitToReadAsync(token).ConfigureAwait(false))
                    {
                        while (reader.TryRead(out _))
                        {
                        }

                        plot.Render();

                        Interlocked.Exchange(ref render, 1);

                        await plot.StateHasChangedAsync().ConfigureAwait(false);

                        try
                        {
                            await semaphore.WaitAsync(token).ConfigureAwait(false);
                        }
                        finally
                        {
                        }
                    }
                }
                catch (Exception e)
                {
                }
            }, TaskCreationOptions.LongRunning);
        }