在asp.net多线程 [英] multi threading on asp.net

查看:188
本文介绍了在asp.net多线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有用多线程多的asp.net。我有一个上传大量临时文件到文件夹的Web应用程序。我想它上传后,采取临时文件,并做一些其他的事情吧。我可以做另一个线程这项工作不容易被用户在网站上了吗?感谢您的任何帮助或建议。

1.用户后大文件
2.uploading临时服务器
3.After上传完成。我想运行其他线程/工人,可以无需任何用户迭代运行,但是触发用户。

 上传无效(){
//上传文件到服务器
}
无效Submitclick(){
启动一个线程
线程线程=新主题(DoThreadWork); //用户是否还需要先登录?
发送到另一个页面
}
无效DoThreadWork(){在后台执行此}


解决方案

这是绝对有可能,我使用的后台线程颇有几分在ASP.NET中做一些时髦的东西。如果您对服务器的完全控制它可能是更优雅在一个单独的应用程序或Windows服务运行的后台code。

这是一个较好的分离关注有你的IIS应用程序处理的只是响应Web请求,并且它没有作好准备的。

另外一个警告,如果你在ASP.NET 2.0中有一个后台线程,它有未处理的异常,则默认为重置应用程序池。

点击此处了解详情:<一href=\"http://blogs.msdn.com/b/tess/archive/2006/04/27/584927.aspx\">http://blogs.msdn.com/b/tess/archive/2006/04/27/584927.aspx

// 3 downvotes?

听着,它不必总是尽量避免运行在后台线程的东西。我已经在几种情况下打这个:


  • 我在一家公司工作过与不合理的态度软件
    我们不允许部署一个单独的应用程序来处理
    后台处理。我主张一个窗口服务,但
    否决并告诉来实现它在后台线程。明显
    我与该公司的一个健康的环境继续前行,但就是
    现实就是这样,你必须处理不合理的情况下,
    有时。

  • 如果您在托管环境是你并不总是要卸载到一个单独的进程的选项。

的问题是,如果它是可能的。我回答这个问题。

I have not used multi threading much for asp.net. I have a web application that uploads a large temp file to folder. I would like to take that temp file and do some other things with it after it is uploaded. Can I do this work on another thread without the user being on the website any more? Thanks for any help or suggestions.

1.User post large file 2.uploading temp to server 3.After upload completes. I would like to run another thread/worker that can run without any user iteration but is trigger by the user.

void uploading(){
//Uploading file To server
}
void Submitclick(){
Start a Thread 
Thread thread = new Thread(DoThreadWork);// does the user still need to be logged in?
Send to another page
}
void DoThreadWork(){Do this in background}

解决方案

It's definitely possible, I've used background threads quite a bit in ASP.NET to do some funky stuff. If you have complete control over the server it might be more elegant to run the background code in a separate application or a windows service.

It's a better separation of concerns to have your IIS app dealing with just responding to web requests, and it's not geared up for that.

Also a warning, if you have a background thread in ASP.NET 2.0 and it has an unhandled exception, the default is to reset the application pool.

More information here: http://blogs.msdn.com/b/tess/archive/2006/04/27/584927.aspx

// 3 downvotes?

Listen, it's not alway possible to avoid running something in a background thread. I've hit this in several situations:

  • I've worked in a company with an unreasonable attitude to software where we were not allowed to deploy a separate app to handle the background processing. I argued for a windows service, but was overruled and told to implement it in a background thread. Obviously I moved on from that company to a healthier environment, but that is the reality is this you have to deal with unreasonable situations sometimes.
  • if you're in a hosted environment you don't always have the option to offload onto a seperate process.

The question was if it is possible. I'm answering that question.

这篇关于在asp.net多线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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