在ASP.NET Web应用程序正确的方法来创建线程 [英] right way to create thread in ASP.NET web application

查看:96
本文介绍了在ASP.NET Web应用程序正确的方法来创建线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建ASMX Web服务,必须创建线程做背景的IO刷新系统数据。什么是正确的方法是什么?我没有兴趣得到任何结果,以创建线程。我只是想ASP.NET辅助线程创建一个线程,做它的装载和最终令人分配(我认为分配_alldata = newData是原子在哪里我自己的大结构类SystemData的两个实例),从而创建工作线程在新的线程可以即时传播。

i'm creating asmx web service and have to create thread to do background IO to refresh system data. What is the right way? I'm not interested to get any results to creating thread. I just want the ASP.NET worker thread to create a thread that does it's loading and in the end makes one assign (I think assign _alldata = newData is atomic where both instances of my own big structure class SystemData) so the worker thread that created the the new thread can propagate instantly.

我读到一篇文章<一个href=\"http://msdn.microsoft.com/fi-fi/magazine/cc164128%28en-us%29.aspx#S2\">http://msdn.microsoft.com/fi-fi/magazine/cc164128%28en-us%29.aspx#S2这表明使用非线程池线程。然而,这篇文章是关于不同/更复杂的场景,并没有帮助我这么多。

I read an article http://msdn.microsoft.com/fi-fi/magazine/cc164128%28en-us%29.aspx#S2 which suggest to use non-threadpool thread. The article however was about different / more complex scenario and didn't help me so much.

感谢:马蒂

PS。我曾问过这个问题也是在<一个href=\"http://stackoverflow.com/questions/1820770/what-is-the-right-way-to-spawn-thread-for-database-io-in-asmx-web-service\">http://stackoverflow.com/questions/1820770/what-is-the-right-way-to-spawn-thread-for-database-io-in-asmx-web-service但是,这是与多个问题太复杂。

PS. I have asked this question also in http://stackoverflow.com/questions/1820770/what-is-the-right-way-to-spawn-thread-for-database-io-in-asmx-web-service but that was too complex with multiple questions.

推荐答案

事情是这样的:

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
}

然后得到的东西,通过调用启动初始化(工作)

如果你调用的BeginInvoke() ThreadPool.QueueUserWorkItem(),它使用ASP.NET线程池线程,这会影响你的应用程序的可伸缩性。

If you call BeginInvoke() or ThreadPool.QueueUserWorkItem(), it uses an ASP.NET thread pool thread, which can impact the scalability of your application.

在情况下,它是非常有用的,我详细讨论这些问题,在我的书,用code的例子,样本标准等一起:超快ASP.NET

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.

这篇关于在ASP.NET Web应用程序正确的方法来创建线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆