110,566
社区成员
发帖
与我相关
我的任务
分享
string sql = @"
DECLARE @i int
SELECT @i = COUNT(*) FROM xxxx WHERE groupId = @gid
IF @i = 0
INSERT INTO xxxxxGroup(groupId) VALUES(@gid)";
SqlCommand cmd = new SqlCommand(sql,conn);
....
...
s.tmr.Dispose();
s.tmr = null;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace ConsoleApplication3
{
class TimerExampleState
{
public int counter = 0;
public Timer tmr;
}
class Program
{
static void Main(string[] args)
{
TimerExampleState s = new TimerExampleState();
// Create the delegate that invokes methods for the timer.
TimerCallback timerDelegate = new TimerCallback(CheckStatus);
// Create a timer that waits one second, then invokes every second.
Timer timer = new Timer(timerDelegate, s, 1000, 1000);
// Keep a handle to the timer, so it can be disposed.
s.tmr = timer;
// The main thread does nothing until the timer is disposed.
while (s.tmr != null)
Thread.Sleep(0);
Console.WriteLine("Timer example done.");
}
// The following method is called by the timer's delegate.
static void CheckStatus(Object state)
{
TimerExampleState s = (TimerExampleState)state;
s.counter++;
//写你要执行的命令(执行sql脚本)
Console.WriteLine(s.counter);
//Dispose()
/*
s.tmr.Dispose();
s.tmr = null;
*/
}
}
}