设为首页 加入收藏

TOP

c#实现用SQL池(多线程),定时批量执行SQL语句 【转】(二)
2019-09-17 18:58:11 】 浏览:64
Tags:实现 SQL 线程 定时 批量 执行 语句
t;param name="obj"></param> public void ExecuteSQL(object obj) { if (this.poolOfSQL.Count > 0) { string[] array = this.poolOfSQL.Clear(); //遍历array,执行SQL for (int i = 0; i < array.Length; i++) { if (array[i].ToString().Trim() != "") { try { //数据库操作 //...... } catch { } } } } } #endregion } }

 

 

(三)定时触发SQL执行线程

  总结有以下三种方法,具体请参见http://www.cnblogs.com/tianzhiliang/archive/2010/08/31/1813928.html

方法一:调用线程执行方法,在方法中实现死循环,每个循环Sleep设定时间;

方法二:使用System.Timers.Timer类;

方法三:使用System.Threading.Timer;

  代码如下:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Threading;

namespace Test1
{

    class Program
    {
        static void Main(string[] args)
        {
            //向SQL池中抛入SQL语句
            SQLPoolManage.sqlPoolManage.PushSQL("delete from tbl_test where id = 1");

            //定时触发SQL执行线程
            System.Threading.Timer threadTimer = new System.Threading.Timer(new System.Threading.TimerCallback(SQLPoolManage.sqlPoolManage.ExecuteSQL), null, 0, 100);

            Console.ReadLine();
        }
    }
}

 
 
 
首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇c# 多线程 --Mutex(互斥锁) 【.. 下一篇开发 C# OPC 客户端

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目