我正在工作的一个asp.net MVC-5网络项目,在那里,我必须发送每日电子邮件给所有用户。我知道有两种方法可以做到这一点:
我决定使用Windows服务。我正在开发VisualStudio2013forWeb的Express版本,因此Windows服务模板不在其中。在深入研究之后,我在Visual中创建了一个作为控制台应用程序的windows服务。下面是代码:
服务
public class FirstService : ServiceBase
{
public FirstService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
this.EventLog.WriteEntry("FirstService Service Has Started");
}
protected override void OnStop()
{
this.EventLog.WriteEntry("FirstService Service Has Stopped");
}
private void InitializeComponent()
{
this.ServiceName = "FirstService";
this.CanStop = true;
this.AutoLog = false;
this.EventLog.Log = "Application";
this.EventLog.Source = "FirstService";
}
}安装程序
[RunInstaller(true)]
public class MyServiceInstaller : Installer
{
private ServiceProcessInstaller FirstServiceProcessInstaller;
private ServiceInstaller FirstServiceInstaller;
public MyServiceInstaller()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.FirstServiceProcessInstaller = new ServiceProcessInstaller();
this.FirstServiceProcessInstaller.Account = ServiceAccount.LocalSystem;
this.FirstServiceProcessInstaller.Username = null;
this.FirstServiceProcessInstaller.Password = null;
this.FirstServiceInstaller = new ServiceInstaller();
this.FirstServiceInstaller.Description = "FirstService Service Template";
this.FirstServiceInstaller.DisplayName = "First Service";
this.FirstServiceInstaller.ServiceName = "FirstService";
this.FirstServiceInstaller.StartType = ServiceStartMode.Manual;
this.Installers.AddRange(new Installer[] { this.FirstServiceProcessInstaller, this.FirstServiceInstaller });
}
}主
static class Program
{
[STAThread]
static void Main()
{
ServiceBase.Run(new FirstService());
}
}在此之后,我已经成功地使用installutil.exe安装了此服务,并且可以成功地从控制面板、->管理工具、->系列中启动和停止服务。在此之前,一切都很好。
现在,正如我前面提到的,我想在我的mvc-5应用程序中使用windows服务向我的应用程序用户发送自动电子邮件,我有一些问题:
如果可能的话,请向我推荐包含此示例的任何好教程。谢谢!
发布于 2014-01-15 13:43:16
让我再提出两种选择:
我不明白在mvc应用程序中集成windows服务是什么意思。
它们是两个不同的进程,因此您需要实现进程之间的任何类型的通信(例如,通过数据库、文件、消息传递等)。
发布于 2014-01-15 12:54:12
2&3:您需要遵循与本地开发系统相同的步骤。
希望它能帮上忙
https://stackoverflow.com/questions/21137883
复制相似问题