- using System;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Threading;
- using System.Windows.Forms;
-
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- Thread thread = null;
-
- public Form1()
- {
- InitializeComponent();
- }
-
- /// <summary>
- /// 実行
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void exeBtn_Click(object sender, EventArgs e)
- {
- if (thread == null)
- {
- threadState.Text = "実行中";
- textBox1.Text = "";
- ThreadTest.cnt = 0;
- ThreadTest.exeFlg = true;
-
- thread = new Thread(new ThreadStart(ThreadTest.countUp));
- // 別スレッドの処理開始
- thread.Start();
- }
- }
-
- /// <summary>
- /// 停止
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void stopBtn_Click(object sender, EventArgs e)
- {
- threadState.Text = "停止中";
- ThreadTest.exeFlg = false;
- textBox1.Text = ThreadTest.cnt.ToString();
-
- // スレッド破棄
- thread.Abort();
- thread = null;
- }
- }
- }
|