public class WaitFormService { public static void CreateWaitForm(string message) { WaitFormService.Instance.CreateForm(message); } public static void CloseWaitForm() { WaitFormService.Instance.CloseForm(); } private static WaitFormService _instance; private static readonly Object syncLock = new Object(); public static WaitFormService Instance { get { if (WaitFormService._instance == null) { lock (syncLock) { if (WaitFormService._instance == null) { WaitFormService._instance = new WaitFormService(); } } } return WaitFormService._instance; } } private WaitFormService() { } private Thread waitThread; private Lba_Ciac.Loading waitForm; public void CreateForm(string message) { if (waitThread != null) { try { waitThread.Abort(); } catch (Exception) { } } waitThread = new Thread(new ThreadStart(delegate() { waitForm = new Lba_Ciac.Loading(); waitForm.Text = message; Application.Run(waitForm); })); waitThread.Start(); } public void CloseForm() { if (waitForm != null) { try { waitForm.Invoke((Action)(() => { waitForm.Close(); })); } catch (Exception) { } } if (waitThread != null) { try { waitThread.Abort(); } catch (Exception) { } } } }