Last active
August 29, 2015 13:56
-
-
Save LukaHorvat/8883379 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static Form form; | |
private static Thread thread; | |
private static event Action showRequest; | |
public static void OpenForm() | |
{ | |
if (thread == null) | |
{ | |
thread = new Thread(() => | |
{ | |
form = new Form(); | |
form.Show(); | |
showRequest += delegate | |
{ | |
form.Show(); | |
}; | |
form.FormClosing += delegate(object sender, FormClosingEventArgs args) | |
{ | |
if (args.CloseReason == CloseReason.UserClosing) | |
{ | |
args.Cancel = true; | |
form.Hide(); | |
} | |
}; | |
Application.EnableVisualStyles(); | |
Application.Run(); | |
}); | |
} | |
if (thread.ThreadState != ThreadState.Running) thread.Start(); | |
else | |
{ | |
if (showRequest != null) showRequest.BeginInvoke(null, null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment