Exemplo n.º 1
0
        // ******************************************************************
        private static void StartDlgProgress(DlgProgressModel progressModel, AutoResetEvent resetEvent, List <DlgProgress> listDlgProgressWithProgressStatus)
        {
            DlgProgress dlgProgress = new DlgProgress(progressModel);

            listDlgProgressWithProgressStatus.Add(dlgProgress);
            dlgProgress.ShowDialog();
            resetEvent.Set();
        }
Exemplo n.º 2
0
        // ******************************************************************
        private DlgProgress(DlgProgressModel dlgProgressModel)
        {
            if (dlgProgressModel.Owner == null)
            {
                throw new ArgumentNullException("Owner cannot be null");
            }

            InitializeComponent();
            // this.Owner = owner; // Can't another threads owns it exception

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

            _dlgProgressModel                  = dlgProgressModel;
            _dlgProgressModel.Dispatcher       = this.Dispatcher;
            _dlgProgressModel.PropertyChanged += _dlgProgressModel_PropertyChanged;
            DataContext = _dlgProgressModel;
        }
Exemplo n.º 3
0
        // ******************************************************************
        public static DlgProgress CreateProgressBar(Window owner, DlgProgressModel dlgProgressModel)
        {
            DlgProgress dlgProgressWithProgressStatus     = null;
            var         listDlgProgressWithProgressStatus = new List <DlgProgress>();
            var         resetEvent = new AutoResetEvent(false);

            IntPtr windowHandleOwner = new WindowInteropHelper(owner).Handle;

            dlgProgressModel.Owner       = owner;
            dlgProgressModel.IntPtrOwner = windowHandleOwner;

            var workerThread = new ThreadEx(() => StartDlgProgress(dlgProgressModel, resetEvent, listDlgProgressWithProgressStatus));

            workerThread.Thread.SetApartmentState(ApartmentState.STA);
            workerThread.Start();
            resetEvent.WaitOne(10000);
            if (listDlgProgressWithProgressStatus.Count > 0)
            {
                dlgProgressWithProgressStatus = listDlgProgressWithProgressStatus[0];
            }

            return(dlgProgressWithProgressStatus);
        }