示例#1
0
 private static void HandleCancellation(CreateCollageAsyncContext context, ref bool isCancelled)
 {
     if (context != null)
     {
         if (context.IsCancelling)
         {
             isCancelled = true;
         }
     }
 }
示例#2
0
        public void CreateAsync()
        {
            var worker            = new CreateTaskWorkerDelegate(CreateCollage);
            var completedCallback = new AsyncCallback(CreateTaskCompletedCallback);

            lock (this.sync)
            {
                if (this.isBusy)
                {
                    ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(), "The engine is currently busy.");
                }

                AsyncOperation async   = AsyncOperationManager.CreateOperation(null);
                var            context = new CreateCollageAsyncContext();
                bool           cancelled;
                worker.BeginInvoke(async, context, out cancelled, completedCallback, async);
                this.isBusy            = true;
                this.createTaskContext = context;
            }
        }
示例#3
0
 private void CreateCollage(AsyncOperation async, CreateCollageAsyncContext context, out bool isCancelled)
 {
     isCancelled = false;
     using (var bitmapCollage = new Bitmap(this.settings.Dimensions.TotalWidth, this.settings.Dimensions.TotalHeight))
     {
         using (Graphics graphics = bitmapCollage.CreateGraphics())
         {
             for (int rowsCounter = 0; rowsCounter < this.settings.Dimensions.NumberOfRows; rowsCounter++)
             {
                 for (int colsCounter = 0; colsCounter < this.settings.Dimensions.NumberOfColumns; colsCounter++)
                 {
                     this.ReportProgress(async, colsCounter, rowsCounter);
                     HandleCancellation(context, ref isCancelled);
                     DrawTile(graphics, colsCounter, rowsCounter);
                 }
             }
         }
         this.collageSaver.Save(bitmapCollage);
     }
 }
示例#4
0
        public void CreateAsync()
        {
            var worker = new CreateTaskWorkerDelegate(CreateCollage);
            var completedCallback = new AsyncCallback(CreateTaskCompletedCallback);

            lock (this.sync)
            {
                if (this.isBusy)
                {
                    throw new InvalidOperationException("The engine is currently busy.");
                }

                AsyncOperation async = AsyncOperationManager.CreateOperation(null);
                var context = new CreateCollageAsyncContext();
                bool cancelled;

                worker.BeginInvoke(async, context, out cancelled, completedCallback, async);

                this.isBusy = true;
                this.createTaskContext = context;
            }
        }
示例#5
0
        private void CreateCollage(AsyncOperation async, CreateCollageAsyncContext context, out bool isCancelled)
        {
            isCancelled = false;

            using (var bitmapCollage = new Bitmap(this.settings.Dimensions.TotalWidth, this.settings.Dimensions.TotalHeight))
            {
                using (Graphics graphics = bitmapCollage.CreateGraphics())
                {
                    for (int rowsCounter = 0; rowsCounter < this.settings.Dimensions.NumberOfRows; rowsCounter++)
                    {
                        for (int colsCounter = 0; colsCounter < this.settings.Dimensions.NumberOfColumns; colsCounter++)
                        {
                            this.ReportProgress(async, colsCounter, rowsCounter);
                            HandleCancellation(context, ref isCancelled);

                            DrawTile(graphics, colsCounter, rowsCounter);
                        }
                    }
                }

                this.collageSaver.Save(bitmapCollage);
            }
        }
示例#6
0
 private static void HandleCancellation(CreateCollageAsyncContext context, ref bool isCancelled)
 {
     if (context != null)
     {
         if (context.IsCancelling)
         {
             isCancelled = true;
         }
     }
 }