public WaitBannerFormHolder(WaitBannerForm form, int?visibleDelayInMilliseconds) { _Form = form; if (visibleDelayInMilliseconds.HasValue) { void show_NoThrow() { try { _Form?.Show(); } catch (Exception ex) { Debug.WriteLine(ex); } }; Task.Run(async() => { await Task.Delay(visibleDelayInMilliseconds.Value); await Dispatcher.UIThread.InvokeAsync(show_NoThrow); }); } else { _Form.Show(); } }
public static WaitBannerForm Create(Window owner, CancellationTokenSource cts, string captionText = CAPTION_TEXT, int?visibleDelayInMilliseconds = null) { if (owner == null) { throw (new ArgumentNullException(nameof(owner))); } if (cts == null) { throw (new ArgumentNullException(nameof(cts))); } //------------------------------------------------------------------------// //parent.SuspendDrawing(); //try //{ var form = new WaitBannerForm() { _CancellationTokenSource = cts, _CaptionText = captionText, _VisibleDelayInMilliseconds = visibleDelayInMilliseconds, Owner = owner, }; form.captionLabel.Text = captionText; /* * if ( visibleDelayInMilliseconds.HasValue ) * { * await Task.Delay( visibleDelayInMilliseconds.Value ); * //form.IsVisible = false; * //form._Timer.Interval = Math.Min( 100, visibleDelayInMilliseconds.Value ); * //form._Timer.Enabled = true; * } * form.Show(); */ //parent.Controls.Add( form ); //form.BringToFront(); //form.Anchor = AnchorStyles.None; //form.Location = new Point( (parent.Width - form.Width) / 2, (parent.Height - form.Height) / 2 ); //Application.DoEvents(); return(form); //} //finally //{ // parent.ResumeDrawing(); //} }
public void Dispose() { if (_Form != null) { try { _Form.Close(); _Form = null; } catch (Exception ex) { Debug.WriteLine(ex); } } }
public static IDisposable CreateAndShow(Window owner, CancellationTokenSource cts, string captionText = CAPTION_TEXT, int?visibleDelayInMilliseconds = null) { if (owner == null) { throw (new ArgumentNullException(nameof(owner))); } if (cts == null) { throw (new ArgumentNullException(nameof(cts))); } //------------------------------------------------------------------------// var form = new WaitBannerForm() { _CancellationTokenSource = cts, _CaptionText = captionText, _VisibleDelayInMilliseconds = visibleDelayInMilliseconds, Owner = owner, }; form.captionLabel.Text = captionText; return(new WaitBannerFormHolder(form, visibleDelayInMilliseconds)); }