// ****************************************************************** private static void StartDlgProgress(DlgProgressModel progressModel, AutoResetEvent resetEvent, List <DlgProgress> listDlgProgressWithProgressStatus) { DlgProgress dlgProgress = new DlgProgress(progressModel); listDlgProgressWithProgressStatus.Add(dlgProgress); dlgProgress.ShowDialog(); resetEvent.Set(); }
// ****************************************************************** 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; }
// ****************************************************************** 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); }