Skip to content

Instantly share code, notes, and snippets.

@MiffOttah
Created September 1, 2019 04:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MiffOttah/33bbe9a5dec0a37e953709e03bcae199 to your computer and use it in GitHub Desktop.
Save MiffOttah/33bbe9a5dec0a37e953709e03bcae199 to your computer and use it in GitHub Desktop.
using System;
using System.Threading;
using System.Windows.Forms;
namespace Sandbox
{
public class ExitCompare : Form
{
Thread BackgroundThread = null;
public ExitCompare()
{
SuspendLayout();
var table = new TableLayoutPanel { Dock = DockStyle.Fill, RowCount = 3, ColumnCount = 1 };
table.RowStyles.Add(new RowStyle(SizeType.Percent, 33.33f));
table.RowStyles.Add(new RowStyle(SizeType.Percent, 33.33f));
table.RowStyles.Add(new RowStyle(SizeType.Percent, 33.33f));
Controls.Add(table);
var startThreadButton = new Button
{
Dock = DockStyle.Fill,
TabIndex = 0,
Text = "Start background thread"
};
startThreadButton.Click += StartThread;
table.Controls.Add(startThreadButton, 0, 0);
var applicationExitButton = new Button
{
Dock = DockStyle.Fill,
TabIndex = 1,
Text = "Application.Exit"
};
applicationExitButton.Click += (sender, e) => Application.Exit();
table.Controls.Add(applicationExitButton, 0, 1);
var environmentExitButton = new Button
{
Dock = DockStyle.Fill,
TabIndex = 2,
Text = "Environment.Exit"
};
environmentExitButton.Click += (sender, e) => Environment.Exit(0);
table.Controls.Add(environmentExitButton, 0, 2);
this.Text = "Exit Comparison";
this.ResumeLayout(false);
}
private void StartThread(object sender, EventArgs e)
{
if (BackgroundThread == null)
{
BackgroundThread = new Thread(new ThreadStart(() =>
{
while (true)
{
Thread.Sleep(1000);
Console.WriteLine("Background thread running.");
}
}));
BackgroundThread.Start();
}
((Button)sender).Enabled = false;
}
[STAThread]
public static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new ExitCompare());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment