zoukankan      html  css  js  c++  java
  • 每隔两分钟断开连接

    using System;
    using System.Diagnostics;
    using System.Runtime.InteropServices;
    using System.Threading;
    using System.Timers;
    
    namespace ConsoleApp8
    {
        class Program
        {
            //调用API函数
            [DllImport("kernel32.dll")]
            extern static short QueryPerformanceCounter(ref long x);
            [DllImport("kernel32.dll")]
            extern static short QueryPerformanceFrequency(ref long x);
            public static int j = 0;
            public static int back = 0;
            public static System.Timers.Timer timer = new System.Timers.Timer();
            static void Main(string[] args)
            {
    
                Jishi();
            }
            static void Jishi()
            {
                timer.Interval = 90;//准备计时1秒。程序中可以设置为两分钟120000
                timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
                if (timer.Enabled != true)//判断计时函数是否已经启动了,若没有启动,则可以启动。否则不启动
                {
                    timer.Start();
                }
                if (j == 1)//等于1说明代码为离线状态,退出方法
                {
                    return;
                }
                else//继续等待下次循环
                {
                    SetTime();//模拟调用接收untity请求的方法
                    timer.Interval = 90;//重新准备计时1秒。程序中可以设置为两分钟120000
                    timer.Start();
                    Jishi();
                }
            }
            private static void OnTimedEvent(object source, ElapsedEventArgs e)
            {
                j = 1;//j等于1,表示将代码置为离线状态了
                timer.Stop();//停止计时
                return;//退出方法
            }
            /// <summary>
            /// 模拟接收untity的请求(就是个耗时操作)
            /// </summary>
            static void SetTime()
            {
                for (int i = 0; i < 330; i++)
                {
                    Console.WriteLine(i);
                }
            }
        }
    }
  • 相关阅读:
    runc create container 流程分析
    cri-o pod 创建源码分析
    hyperstart 容器创建流程分析
    MIT jos 6.828 Fall 2014 训练记录(lab 4)
    python 邮件发送 脚本
    jvm: 理解gc日志
    jvm:垃圾收集器
    GC 垃圾收集
    jvm结构
    Java transient关键字使用小记
  • 原文地址:https://www.cnblogs.com/HuangLiming/p/14790813.html
Copyright © 2011-2022 走看看