螺纹asp.net/c# [英] thread in asp.net/c#

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

问题描述

我要上USER_LOGIN事件或Fo​​rm_Load事件中创建线程。
在这个线程我要调用一个类函数来执行一些SQL语句,并且用户不必等待结果或后台进程完成,他只是针对自己的需要的页面让说我的个人资料或什么都。
我使用ASP.NET,C#。

I want to create a thread on user_login Event or Form_load Event. In this thread i want to call a class function to execute some sql statement, and the user do not have to wait for the result or background process to be finished, he is just directed to his desired page let say my profile or what ever. I am using ASP.NET, C#.

推荐答案

对于什么是值得的,这是一个坏主意。有多种的方式,就是IIS可以终止后台线程(IIS重新启动,应用程序池重启,等等,所有这些都是IIS的正常预期行为),其结果将是你的数据库事务都默默回滚。

For what it is worth, this is a Bad Idea. There are a variety of ways that that IIS could terminate that background thread (IIS restart, app pool restart, etc., all of which are normal expected behavior of IIS), and the result would be that your DB transaction gets silently rolled back.

如果这些查询需要可靠地执行,您应在请求执行它们或发送给Windows服务或其他长期的过程。这并不意味着用户不能在progress- IIS请求本身可以通过一个AJAX调用执行得到反馈。

If these queries need to be reliably executed, you should either execute them in the request or send them to a windows service or other long-lived process. This doesn't mean that the user can't get feedback on the progress- the IIS request itself could be executed via an AJAX call.

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

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