Phil Haack wrote a great article on the dangers of recurring background tasks in ASP.NET
http://haacked.com/archive/2011/10/16/the-dangers-of-implementing-recurring-background-tasks-in-asp-net.aspx/
http://ayende.com/blog/155489/rotten-scheduling-dont-roll-your-own#comments
Un montón de alternativas como HangFire (por la que pregunto en este caso), Quarz.net y muchas más
http://www.hanselman.com/blog/HowToRunBackgroundTasksInASPNET.aspx
http://blog.koalite.com/2012/05/programacion-de-tareas-con-quarz-net/
--
Has recibido este mensaje porque estás suscrito al grupo "AltNet-Hispano" de Grupos de Google.
Para cancelar la suscripción a este grupo y dejar de recibir sus mensajes, envía un correo electrónico a altnet-hispano+unsubscribe@googlegroups.com.
Para publicar en este grupo, envía un correo electrónico a altnet-hispano@googlegroups.com.
Visita este grupo en https://groups.google.com/group/altnet-hispano.
Para acceder a más opciones, visita https://groups.google.com/d/optout.
Para publicar en este grupo, envía un correo electrónico a altnet-...@googlegroups.com.
Visita este grupo en https://groups.google.com/group/altnet-hispano.
Para acceder a más opciones, visita https://groups.google.com/d/optout.
Para cancelar la suscripción a este grupo y dejar de recibir sus mensajes, envía un correo electrónico a altnet-hispan...@googlegroups.com.
Para publicar en este grupo, envía un correo electrónico a altnet-...@googlegroups.com.
Visita este grupo en https://groups.google.com/group/altnet-hispano.
Para acceder a más opciones, visita https://groups.google.com/d/optout.
--
Has recibido este mensaje porque estás suscrito al grupo "AltNet-Hispano" de Grupos de Google.
Para cancelar la suscripción a este grupo y dejar de recibir sus mensajes, envía un correo electrónico a altnet-hispan...@googlegroups.com.
Para cancelar la suscripción a este grupo y dejar de recibir sus mensajes, envía un correo electrónico a altnet-hispano+unsubscribe@googlegroups.com.
Para publicar en este grupo, envía un correo electrónico a altnet-hispano@googlegroups.com.
public
class
WcfServiceWrapper<TServiceImplementation, TServiceContract>
: ServiceBase
where
TServiceImplementation : TServiceContract
{
private
readonly
string
_serviceUri;
private
ServiceHost _serviceHost;
public
WcfServiceWrapper(
string
serviceName,
string
serviceUri)
{
_serviceUri = serviceUri;
ServiceName = serviceName;
}
protected
override
void
OnStart(
string
[] args)
{
Start();
}
protected
override
void
OnStop()
{
Stop();
}
private
static
void
Main(
string
[] args)
{
var
host = HostFactory.New(c =>
{
c.Service<WcfServiceWrapper<Calculator, ICalculator>>(s =>
{
s.SetServiceName(
"CalculatorService"
);
s.ConstructUsing(x =>
new
WcfServiceWrapper<Calculator, ICalculator>(
"Calculator"
, serviceUri));
s.WhenStarted(service => service.Start());
s.WhenStopped(service => service.Stop());
});
c.RunAsLocalSystem();
c.SetDescription(
"Runs CalculatorService."
);
c.SetDisplayName(
"CalculatorService"
);
c.SetServiceName(
"CalculatorService"
);
});
Console.WriteLine(
"Hosting ..."
);
host.Run();
Console.WriteLine(
"Done hosting ..."
);
}
First run it as a console application
>Calculator.exe
Hosting ...
Calculator starting...
Calculator started at http://localhost:10000/calc
>Calculator.exe install
Hosting ...
Running a transacted installation.
Beginning the Install phase of the installation.
Installing service CalculatorService...
Service CalculatorService has been successfully installed.
Creating EventLog source CalculatorService in log Application...
The Install phase completed successfully, and the Commit phase is beginning.
The Commit phase completed successfully.
The transacted install has completed.
Done hosting ...
>Calculator.exe uninstall
Hosting ...
The uninstall is beginning.
Removing EventLog source CalculatorService.
Service CalculatorService is being removed from the system...
Service CalculatorService was successfully removed from the system.
Attempt to stop service CalculatorService.
The uninstall has completed.
Done hosting ...
Felices Fiestas. Happy coding!
Dónde encajaría Hangfire para tenerlo "alojado" en un Windows Service utilizando TopShelf? Se queda esperando peticiones...?Salu2
--
Has recibido este mensaje porque estás suscrito al grupo "AltNet-Hispano" de Grupos de Google.
Para cancelar la suscripción a este grupo y dejar de recibir sus mensajes, envía un correo electrónico a altnet-hispano+unsubscribe@googlegroups.com.
public class Startup | |
{ | |
public void Configuration(IAppBuilder app) | |
{ | |
app.UseHangfireDashboard(); | |
} | |
} |
BackgroundJob.Enqueue(() => MethodToRun(42, "foo")); |
Run the Hangfire Server in a Separate Process
Saludos gente!!
--
Has recibido este mensaje porque estás suscrito al grupo "AltNet-Hispano" de Grupos de Google.
Para cancelar la suscripción a este grupo y dejar de recibir sus mensajes, envía un correo electrónico a altnet-hispan...@googlegroups.com.
Configuration
GlobalConfiguration.Configuration
.UseSqlServerStorage(GetConnectionStringBuilder().ConnectionString)
.UseMsmqQueues(@“FormatName:Direct=OS:localhost\hangfire-{0}”);
Starting Server
server = new BackgroundJobServer();
Queuing Job
var manager = new RecurringJobManager();
manager.AddOrUpdate(“Rec-Show-Message”,Job.FromExpression(() => ShowMessage()), Cron.Minutely());
Unable to see any queue created in MSMQ or Job getting executed. I have already configured DTC by following the link: [http://nthrbldyblg.blogspot.com/2017/02/msmq-between-two-computers.html 1]
Added the following code before configuration and MSMQ started working.
var queuePath = @".\Private$";
var queueName = “YourQueueName”;
if (!MessageQueue.Exists(string.Format("{0}{1}", queuePath, queueName)))
{
var queue = MessageQueue.Create(string.Format("{0}{1}", queuePath, queueName), true);
queue.Label = “Your Queue Description”;
}