using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace POSV { internal partial class WaitWindowGUI :Form { private WaitWindow _Parent; private delegate T FunctionInvoker(); internal object _Result; internal Exception _Error; private IAsyncResult threadResult; public WaitWindowGUI(WaitWindow parent) { InitializeComponent(); this._Parent = parent; this.Top = Screen.PrimaryScreen.WorkingArea.Top + 32; this.Left = Screen.PrimaryScreen.WorkingArea.Right - this.Width - 32; } protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { base.OnPaint(e); } protected override void OnShown(EventArgs e) { base.OnShown(e); FunctionInvoker threadController = new FunctionInvoker(this.DoWork); this.threadResult = threadController.BeginInvoke(this.WorkComplete, threadController); } internal object DoWork() { WaitWindowEventArgs e = new WaitWindowEventArgs(this._Parent, this._Parent._Args); if ((this._Parent._WorkerMethod != null)) { this._Parent._WorkerMethod(this, e); } return e.Result; } private void WorkComplete(IAsyncResult results) { if (!this.IsDisposed) { if (this.InvokeRequired) { this.Invoke(new WaitWindow.MethodInvoker(this.WorkComplete), results); } else { try { this._Result = ((FunctionInvoker)results.AsyncState).EndInvoke(results); } catch (Exception ex) { this._Error = ex; } this.Close(); } } } internal void SetMessage(string message) { this.MessageLabel.Text = message; } internal void Cancel() { this.Invoke(new MethodInvoker(this.Close), null); } } }