using Quartz;
using System;
using System.IO;
using Topshelf;
using Topshelf.Quartz;
namespace FinyaConsole
{
class Program
{
static void Main(string[] args)
{
HostFactory.Run(x =>
{
x.Service<MyService>(s =>
{
s.WhenStarted(service => service.OnStart());
s.WhenStopped(service => service.OnStop());
s.ConstructUsing(() => new MyService());
s.ScheduleQuartzJob(q =>
q.WithJob(() =>
JobBuilder.Create<MyJob>().Build())
.AddTrigger(() => TriggerBuilder.Create()
.WithSimpleSchedule(b => b
.WithIntervalInSeconds(10)
.RepeatForever())
.Build()));
});
x.RunAsLocalSystem()
.DependsOnEventLog()
.StartAutomatically()
.EnableServiceRecovery(rc => rc.RestartService(1));
x.SetServiceName("FinyaHearts");
x.SetDisplayName("FinyaGiveHearts");
x.SetDescription("This service is used to give hearts to the users after three days to whom have visited your profiles.");
});
}
}
public class MyService
{
public void OnStart()
{
}
public void OnStop()
{
}
}
public class MyJob : IJob
{
public void Execute(IJobExecutionContext context)
{
try
{
//Pass the filepath and filename to the StreamWriter Constructor
StreamWriter sw = new StreamWriter(".\\visits_to_others.txt", true);
//Write a line of text
sw.WriteLine($"[{DateTime.Now}] Welcome from MyJob!");
//System.IO.File.WriteAllText(@"path\visit_users.txt", userLink);
//Close the file
sw.Flush();
sw.Close();
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.Message);
}
finally
{
//Console.WriteLine("Executing finally block.");
}
}
}
}
--
You received this message because you are subscribed to the Google Groups "topshelf-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to topshelf-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.