You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.4 KiB
C#

9 months ago
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<T>();
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<object> threadController = new FunctionInvoker<object>(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<IAsyncResult>(this.WorkComplete), results);
}
else
{
try
{
this._Result = ((FunctionInvoker<object>)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);
}
}
}