protected virtual void OnRun() { if (MainForm == null) { OnCreateMainForm(); if (MainForm == null) { throw new NoStartupFormException(); } MainForm.Load += MainFormLoadingDone; } try { Application.Run(m_AppContext); } finally { if (m_NetworkObject != null) { m_NetworkObject.DisconnectListener(); } if (m_FirstInstanceSemaphore != null) { m_FirstInstanceSemaphore.Close(); m_FirstInstanceSemaphore = null; } AsyncOperationManager.SynchronizationContext = m_AppSyncronizationContext; m_AppSyncronizationContext = null; } }