Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement