private void CloseForm() { if (this.InvokeRequired) { SetCloseCallback d = new SetCloseCallback(CloseForm); if (this.IsHandleCreated && !this.IsDisposed) { try { this.Invoke(d, new object[] { }); } catch { } } } else { this.Close(); } }
private void SetClose() { // InvokeRequired required compares the thread ID of the // calling thread to the thread ID of the creating thread. // If these threads are different, it returns true. if (this.InvokeRequired) { SetCloseCallback d = new SetCloseCallback(SetClose); try { this.Invoke(d, new object[] { }); } catch (Exception) { } } else { this.Close(); } }