zoukankan      html  css  js  c++  java
  • 关于线程(一)

       主要是怎么监控一个线程正在运行 用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);
                       
                    }
                }
            }

  • 相关阅读:
    SpringBoot的多环境配置及配置文件位置
    SpringBoot;yaml配置, JSR303校验
    springboot原理探寻,自动装配
    SpringBoot入门:搭建SpringBoot
    Android控件阴影库
    Android开发Utils工具类集合
    Android 实现顶部状态栏的沉浸模式(任意设置状态栏的颜色)
    推荐一个博客代码高亮插件
    H5+Css+js 做App UI 与原生的区别
    Android线程切换简便方法
  • 原文地址:https://www.cnblogs.com/hanjiaxu/p/3096705.html
Copyright © 2011-2022 走看看