Something like this:
public delegate void Worker();
private static Thread worker;
public static void Init(Worker work)
{
worker = new Thread(new ThreadStart(work));
worker.Start();
}
public static void Work()
{
// do stuff
}
Then get things started by calling Init(Work)
.
If you call BeginInvoke()
or ThreadPool.QueueUserWorkItem()
, it uses an ASP.NET thread pool thread, which can impact the scalability of your application.
In case it's useful, I cover these issues in detail in my book, along with code examples, sample benchmarks, etc: Ultra-Fast ASP.NET.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…