using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Linq; using System.Text; using System.Threading; using System.Windows.Forms; namespace Core.Mes.Client.Comm.Control { internal delegate void MDelegate(); public class WaitingForm2 { private Thread _thread; private WaitingFrm _form; private string _msg = ""; public string Msg { get { return _msg; } set { _msg = value; } } private bool _showToUser = false; public bool ShowToUser { get { return _showToUser; } set { if (!value) { Close(); } _showToUser = value; } } public int Height { get { return _form.Height; } set { _form.Height = value; } } public int Width { get { return _form.Width; } set { _form.Width = value; } } public WaitingForm2() { _form = new WaitingFrm(); _thread = new Thread(Run); } public WaitingForm2(string msg) { _form = new WaitingFrm(); _form.Label1.Text = msg; _thread = new Thread(Run); _thread.Start(); } public void Show() { _form.Label1.Text = _msg; _thread.Start(); } private void Run() { try { _form.PictureBox1.Image = Image.FromFile(Environment.CurrentDirectory + "\\images\\load.gif"); if (_thread.ThreadState == ThreadState.Running) { _form.ShowDialog(); } } catch (Exception ex) { } finally { } } public void Close() { try { if (_form.InvokeRequired) { _form.Invoke(new MDelegate(() => { _form.Hide(); _form.Close(); _form.Dispose(); })); } else { _form.Hide(); _form.Close(); _form.Dispose(); } } catch (Exception ex) { } finally { try { Thread.Sleep(100); if(_thread.IsAlive) _thread.Abort(); } catch (Exception ex) { } } } public void Update() { } } }