構思:寫一個全局的Queue , 然後開一個線程去循環. 不善言語,直接看代碼吧!
public class MyQueue
{
public decimal Id { get; set; }
public decimal Type { get; set; }
}
static Queue<MyQueue> TaskQueue = new Queue<MyQueue>();
static void Main(string[] args)
{
ServiceStart();
Console.ReadLine();
}
public static void ServiceStart()
{
Thread TaskThread = new Thread(new ThreadStart(ThreadInvoke));
TaskThread.IsBackground = true;
TaskThread.Start();
}
public static void ThreadInvoke()
{
while (true)
{
string m_time = DateTime.Now.ToString("HH:mm:ss");
if (m_time == Invoke_Time) //判斷是否指定時間(Invoke_Time)
{
//InitTaskQueue();//初始化隊列
while (TaskQueue.Count > 0)
{
MyQueue m_mq = null;
lock (TaskQueue)
{
m_mq = TaskQueue.Dequeue();
}
//YourMethd(m_mq.UserId, m_mq.FeedTypeId); //調用方法
//Common.Log.Logger.Info(DateTime.Now.ToString()); //記錄日志
Thread.Sleep(100);
}
}
Thread.Sleep(100);
}
}