﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace IceBuilder
{

    public interface UpgradeProgressCallback
    {
        bool Canceled { get; set; }
        void Finished();
        void ReportProgress(String project, int index);
    }

    public partial class UpgradeDialogProgress : Form, UpgradeProgressCallback
    {
        public UpgradeDialogProgress(int total)
        {
            InitializeComponent();
            ProgressBar.Maximum = total;
        }

        private void CancelButton_Clicked(object sender, EventArgs e)
        {
            Canceled = true; 
        }

        public bool Canceled
        {
            get;
            set;
        }

        public void ReportProgress(String project, int index)
        {
            InfoLabel.Text = String.Format("Upgrading project: {0}", project);
            ProgressBar.Value = index;
        }

        public void Finished()
        {
            Close();
        }
    }
}

﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace IceBuilder
{

    public interface UpgradeProgressCallback
    {
        bool Canceled { get; set; }
        void Finished();
        void ReportProgress(String project, int index);
    }

    public partial class UpgradeDialogProgress : Form, UpgradeProgressCallback
    {
        public UpgradeDialogProgress(int total)
        {
            InitializeComponent();
            _canceled = false;
            ProgressBar.Maximum = total;
        }

        private void CancelButton_Clicked(object sender, EventArgs e)
        {
            Canceled = true; 
        }

        private bool _canceled;
        public bool Canceled
        {
            get
            {
                lock (this)
                {
                    return _canceled;
                }
            }
            set
            {
                lock (this)
                {
                    _canceled = value;
                }
            }
        }

        public void ReportProgress(String project, int index)
        {
            InfoLabel.Text = String.Format("Upgrading project: {0}", project);
            ProgressBar.Value = index;
        }

        public void Finished()
        {
            Close();
        }
    }
}

Fix possible race condition in the Upgrade Callback
Fix possible race condition in the Upgrade Callback
