我的asp.net后台程序中有两个线程,一个队列(Queue myQueue)。
其中一个线程是用来接受对方通过url发送过来的数据,并将数据添加到队列(myQueue.EnQueue());
另一个线程用来不断从队列中取出数据,并处理。
我的问题是,我如何能确保第二个线程不断的执行;
这如果在WinForm下不难实现,无非是使用一个Timer,可我对WebForm的运行机理不是很了解,我在猜想WebForm是不是只有在接受url的时候才运行?!
请高手指点,多谢拉!
其中一个线程是用来接受对方通过url发送过来的数据,并将数据添加到队列(myQueue.EnQueue());
另一个线程用来不断从队列中取出数据,并处理。
我的问题是,我如何能确保第二个线程不断的执行;
这如果在WinForm下不难实现,无非是使用一个Timer,可我对WebForm的运行机理不是很了解,我在猜想WebForm是不是只有在接受url的时候才运行?!
请高手指点,多谢拉!
解决方案 »
- GridView中自定义增加一个HyperLinkField类型,如何将此按钮链接到服务器端的代码?
- c# 如何将DataTable转为string[,]或者string[][]数组或者arrarlist?
- c# 与 vb转化问题
- 重新理解!
- 急需C#如何开发数据处理软件
- 求wise for .net中文版或中文补丁!!!
- 不明白!HTML和WEB窗体都有image及其他相同的控件,问他们能实现相同的功能吗?有区别吗?
- 看了ahui_net (阿灰) 的帖子有感,顺便散分。
- 一个百思不得其解的问题,大家来看看!
- string format 对齐问题
- 求教:C#中有没有延时函数啊,比如Sleep,Delay之类的
- 请教:如何将一个Stream类型的流写入一个文件中
using System;
using System.Threading;class TimerExampleState
{
public int counter = 0;
public Timer tmr;
}class App
{
public static void Main()
{
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++;
Console.WriteLine("{0} Checking Status {1}.",DateTime.Now.TimeOfDay, s.counter);
if(s.counter == 5)
{
// Shorten the period. Wait 10 seconds to restart the timer.
(s.tmr).Change(10000,100);
Console.WriteLine("changed...");
}
if(s.counter == 10)
{
Console.WriteLine("disposing of timer...");
s.tmr.Dispose();
s.tmr = null;
}
}
}
Simulate a Windows Service using ASP.NET to run scheduled jobs
Run scheduled jobs 24x7 using ASP.NET without requiring a Windows Service.
http://www.codeproject.com/aspnet/ASPNETService.asp