在ASP.Net中进行线程化 [英] Threading in ASP.Net

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

问题描述



我有asp.net网络应用程序。每12小时我想做点什么 - 查看一些数据,然后发送电子邮件。正在为这个线程提供良好的解决方案。有没有人有例子?



如果我喜欢那个

  public   delegate   void  Worker(); 
private static 线程工作者;

public static void Init(工作人员工作)
{
worker = new 线程( new ThreadStart(work));
worker.Start();
}

public static void Work()
{
AppLogic.SendMailTo( Something Something true some.mail@gmail.com);

}



并打电话给线程

 Init(工作); 



然后每当有人访问此页面时,asp就会发送邮件。我如何每12个月发送一次这封电子邮件?



谢谢

解决方案

不,线程不是很好的解决方案。 ASP.NET代码仅在从浏览器收到请求时运行。它不是一直在运行。



这个要求最好是由Windows中的Scheduled Task服务执行的控制台应用程序。


< blockquote>查看我过去的回答 - 如何发送来自Asp.net的自动消息C#? [ ^ ]。



您应该为此类任务使用任务计划程序。

Hi,
i have asp.net web application. Every 12 hours i want to do something - check some data and then send the email. Is threading good soluton for this. Does anyone has an example?

If i do like that

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()
{
    AppLogic.SendMailTo("Something", "Something", true, "some.mail@gmail.com");

}


and call whis thread

Init(Work);


Then asp send mail every time, when someone visits this page. How can i send this email every 12 hurs?

Thanks

解决方案

No, threading is NOT a good solution to this. ASP.NET code only runs when a request is received from a browser. It's not running all the time.

This requirement is better done as a console application executed by the Scheduled Task service in Windows.


See my past answer - How to send Automatic Messages from Asp.net C#?[^].

You should use a Task Scheduler for this type of Tasks.


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

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