Example #1
0
        private void GeneratePointImpl(MaskForm mf, int amount)
        {
            int current = 0;

            Task progressTask = Task.Run(() =>
            {
                while (current < amount && !CancellationSource.Token.IsCancellationRequested)
                {
                    ProgressHandler?.Report(new CollectionProgressData {
                        value = current, maxValue = amount
                    });
                    Thread.Sleep(100);
                }
            }, CancellationSource.Token);

            Random rnd = new Random();

            HashSet <System.Drawing.Point> tempInsidePoints  = new HashSet <System.Drawing.Point>();
            HashSet <System.Drawing.Point> tempOutsidePoints = new HashSet <System.Drawing.Point>();

            while (current < amount && !CancellationSource.Token.IsCancellationRequested)
            {
                System.Drawing.Point pt = new System.Drawing.Point(rnd.Next(0, mf.Width), rnd.Next(0, mf.Height));

                if (mf.IsInForm(pt))
                {
                    tempInsidePoints.Add(pt);
                }
                else
                {
                    tempOutsidePoints.Add(pt);
                }

                ++current;
            }

            if (!CancellationSource.Token.IsCancellationRequested)
            {
                InsidePoints  = tempInsidePoints;
                OutsidePoints = tempOutsidePoints;
            }

            progressTask.Wait();
            progressTask.Dispose();
        }
        private async Task StageBlockAsync(
            string blockId,
            MemoryStream stream)
        {
            await OperationExecutionHelper.InvokeWithTimeoutRetryAsync <BlockInfo>(
                async() =>
            {
                using MemoryStream uploadStream = new MemoryStream();
                stream.Position = 0;
                await stream.CopyToAsync(uploadStream).ConfigureAwait(false);
                uploadStream.Position = 0;

                return(await _blobClient.StageBlockAsync(blockId, uploadStream).ConfigureAwait(false));
            },
                TimeSpan.FromSeconds(BlockUploadTimeoutInSeconds),
                BlockUploadTimeoutRetryCount,
                isRetrableException : OperationExecutionHelper.IsRetrableException).ConfigureAwait(false);

            ProgressHandler?.Report(stream.Length);
            await stream.DisposeAsync().ConfigureAwait(false);
        }