惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
Vulnerabilities – Threatpost
L
LINUX DO - 热门话题
H
Hacker News: Front Page
Hacker News - Newest:
Hacker News - Newest: "LLM"
L
Lohrmann on Cybersecurity
Cisco Talos Blog
Cisco Talos Blog
O
OpenAI News
S
Securelist
Security Latest
Security Latest
T
Threat Research - Cisco Blogs
H
Heimdal Security Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recorded Future
Recorded Future
Microsoft Azure Blog
Microsoft Azure Blog
MyScale Blog
MyScale Blog
Webroot Blog
Webroot Blog
The Hacker News
The Hacker News
Google Online Security Blog
Google Online Security Blog
Latest news
Latest news
N
Netflix TechBlog - Medium
N
News and Events Feed by Topic
D
Docker
D
DataBreaches.Net
A
About on SuperTechFans
T
Tor Project blog
V
V2EX
G
Google Developers Blog
博客园 - Franky
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
I
InfoQ
H
Help Net Security
V2EX - 技术
V2EX - 技术
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
Security Affairs
SecWiki News
SecWiki News
The Register - Security
The Register - Security
人人都是产品经理
人人都是产品经理
NISL@THU
NISL@THU
小众软件
小众软件
B
Blog
T
Threatpost
P
Palo Alto Networks Blog
博客园 - 【当耐特】
L
LangChain Blog
AWS News Blog
AWS News Blog
月光博客
月光博客
宝玉的分享
宝玉的分享

博客园 - 冷风.net

以OO的思想利用JS來實現五子棋 開放幾個原來寫的js代碼,供大家娛樂一下 使用JS寫的第一個游戲[俄羅斯方塊] 假如現在讓你去說服客戶使用asp.net2.0開發系統,你會怎麼說服呢? 對象化javascript日期控件 - 冷风.net - 博客园 工作排程 防止圖片在WEB頁面上下載 - 冷风.net - 博客园 今天從新整理的大小寫數據轉換 - 冷风.net - 博客园 常用的XPATH說明 XmlHttp在DoNet中的完全应用---前/后台完成分离篇 系统用户权限与角色分析 学习设计模式之Composite 模式 改進Richer的WEB頁面進度條! 学习设计模式之Bridge模式 学习设计模式之生成器(Builder Pattern)模式 再谈Abstract Factory模式来实现数据库操作的类 Factory Method来实现数据库操作的类 不周表結構合併問題 今天下午困惑的問題,終於TMD搞出來了
利用線程實現錠時執行的運行模型
冷风.net · 2005-01-07 · via 博客园 - 冷风.net

利用線程實現錠時執行的運行模型

Posted on 2005-01-07 10:33  冷风.net  阅读(843)  评论(1)    收藏  举报

以下是關於利用線程來定時執行的初步模型

using System;
using System.Data;
using System.Threading;
using System.Windows.Forms;

namespace Win
{
    
/// <summary>
    
///每隔30分鐘運行一次
    
/// </summary>

    public class Timer
    
{
        
/// <summary>是否正在運行</summary>
        public bool bRun;
        
/// <summary>出錯的最多次數</summary>
        public int iCount=10;    

        
public Timer()
        
{
            bRun 
= false;
            
//只用於拋出線程
            Thread myThread = new Thread(new ThreadStart(RunTimer));
            myThread.Start();
        }


        
/// <summary>
        
///  檢測時間與等待時間
        
/// </summary>

        private void RunTimer()
        
{
            
int curM = Int32.Parse(DateTime.Now.Minute.ToString());
            
if((curM==0 || curM==30&& !bRun)
            
{
                bRun 
= true;
                Thread thread 
= new Thread(new ThreadStart(RunMethod));
                thread.Start();
            }

            
else
            
{
                
                
if(curM>30)
                    curM 
= 60-curM;
                
else
                    curM 
= 30-curM;
                MessageBox.Show(curM.ToString());
                Thread.Sleep(curM
*60*1000);
                RunTimer();
            }

        }


        
/// <summary>
        
/// 定時執行的方法
        
/// </summary>

        private void RunMethod()
        
{
            
int iRun = 0;
            
try
            
{
                MessageBox.Show(DateTime.Now.ToString());
                bRun 
= false;
                RunTimer();
            }

            
catch
            
{
                
if(iRun<iCount)    RunMethod();
                
else MessageBox.Show("系統執行問題");
            }

            
finally
            
{
                iRun
++;
            }

        }

        

    }

}