I am working on an asp.net MVC-5 web project where i have to send daily email to all users. And i know there are 2 ways to achieve this:
I have decided to use Windows service . I am working on Express Version of Visual Studio 2013 for Web, so Windows service template is not present in it. After digging a lot i have created a windows service as console application in Visual Studio. Here's the code:
Service
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";
}
}
Installer
[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 });
}
}
Main
static class Program
{
[STAThread]
static void Main()
{
ServiceBase.Run(new FirstService());
}
}
After this i have successfully installed this service using installutil.exe and can successfully start and stop service from Control Panel -> Administrative Tools -> Serivces . Upto this everything is good.
Now as i mention earlier i want to use windows service in my mvc-5 application for sending automatic email to my application users, i have some questions:
Please suggest me any good tutorial which contains the example, if possible. Thanks!
Let me suggest two more options:
I don´t understand what you mean by integrating windows service in your mvc application.
They are two different processes, so you need to implement any sort of communication between processes (eg through database, file, messaging, etc).
2 & 3 : You need to follow the same steps as you did in the local development system.
Hope it helps
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.