• 关于线程(一)


       主要是怎么监控一个线程正在运行 用if(“线程”!= null)来断定正在运行。

       /// <summary>
            /// 创建循环线程 led_Start
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            static void led_Start()
            {
                int p;
                IntPtr gpiodriver = CreateFile("GIO1:", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
                int bytesReturned = 0;

                while (true)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        p = 0x01 + i;

                        DeviceIoControl(gpiodriver, p, null, 0, null, 0, ref bytesReturned, IntPtr.Zero);
                        Thread.Sleep(200);
                        DeviceIoControl(gpiodriver, p + 3, null, 0, null, 0, ref bytesReturned, IntPtr.Zero);
                    }

                }

            }

            private void button_stop_Click(object sender, EventArgs e)
            {
                IntPtr gpiodriver = CreateFile("GIO1:", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
                if (gpiodriver == (IntPtr)(-1))
                {
                    MessageBox.Show("打开GPIO设备失败!");
                }
                else
                {
                    if (led_start != null)
                    {
                        led_start.Abort();
                        int bytesReturned = 0;
                        DeviceIoControl(gpiodriver, 0x04, null, 0, null, 0, ref bytesReturned, IntPtr.Zero);
                        DeviceIoControl(gpiodriver, 0x05, null, 0, null, 0, ref bytesReturned, IntPtr.Zero);
                        //DeviceIoControl(gpiodriver, 0x06, null, 0, null, 0, ref bytesReturned, IntPtr.Zero);
                        //DeviceIoControl(gpiodriver, 0x07, null, 0, null, 0, ref bytesReturned, IntPtr.Zero);
                    }
                    else
                    {
                        int bytesReturned = 0;
                        DeviceIoControl(gpiodriver, 0x04, null, 0, null, 0, ref bytesReturned, IntPtr.Zero);
                        DeviceIoControl(gpiodriver, 0x05, null, 0, null, 0, ref bytesReturned, IntPtr.Zero);
                       
                    }
                }
            }

  • 相关阅读:
    UVA756
    SP30906
    SP32900
    CF940F
    洛谷P5030
    洛谷P5142
    洛谷P2569
    网络流 24 题做题记录
    矩阵
    二分图
  • 原文地址:https://www.cnblogs.com/hanjiaxu/p/3096705.html
Copyright © 2020-2023  润新知