Popular Posts
DNS SERVER LIST Google 8.8.8.8 8.8.4.4 TWNIC 192.83.166.11 211.72.210.250 HiNet 168.95.1.1 168.95.192.1 Seednet 北區 DNS (台北, 桃園, 新竹, 宜蘭, 花蓮, 苗栗) 139.... write 語法: write at [/][<pos>][(<len>)] output 用法: write 'Bruce'. " 輸出常數 Bruce data CNAME(10) value... Regex (Regular Expression) tool Eclipse Regular Expression Tester Java正規表示式工具-Eclipse GUI介面 [Visual Studio 2010] 好用的 Regex 輔助工具
Blog Archive
Stats
Thread sample
class MyThread
{
    private int executeInterval = 15;
    public int ExecuteInterval
    {
        get { return this.executeInterval; }
        set { this.executeInterval = value; }
    }
    private int checkFlagInterval = 1;
    public int CheckFlagInterval
    {
        get { return this.checkFlagInterval; }
        set
        {
            this.checkFlagInterval = value < 1 ? 1 : value;
            this.checkFlagInterval = value > this.executeInterval ? this.executeInterval : value;
        }
    }
    private bool flag = true;
    public bool Flag
    {
        get { return this.flag; }
        set { this.flag = value; }
    }
    public void Run()
    {
        int timeout = 0;
        while (this.flag)
        {
            if ((timeout -= checkFlagInterval) < 1)
            {
                // do something
                timeout = this.executeInterval;
            }
            Thread.Sleep(this.checkFlagInterval * 1000);
        }
    }
}
class Program
{
    static void Main(string[] args)
    {
        MyThread myThread = new MyThread();
        Thread thread = new Thread(new ThreadStart(myThread.Run));
        thread.Start();

        while (myThread.Flag)
        {
            myThread.Flag = Console.Read() != 'q';
        }
    }
}