Skip to content

Instantly share code, notes, and snippets.

@LukaHorvat
Last active August 29, 2015 13:56
Show Gist options
  • Save LukaHorvat/8883379 to your computer and use it in GitHub Desktop.
Save LukaHorvat/8883379 to your computer and use it in GitHub Desktop.
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