I use Hangfire on my Webservers already, so I am familar with the basics of Hangfire.
I am wondering If Hangfire will also work in a pure Windows Forms environment? I am talking about using Hangfire in a Windows Application to execute Background Jobs. At the moment, all my background jobs are performed on different threads in my windows application. But what happens if the application or pc crashes or is shutting down during processing? All my jobs are canceled and no one will see. But hangfire will retry those jobs after application restart and in future, I may create a Windows Service which executes jobs, triggered by other Windows applications.
So my Question is: Has anyone ever tried to use Hangfire this way? Or is this a stupid idea?
most commonly this would be things like updating database entries, sending mails and other long running tasks which should be running under the user account who triggered the job.
At present, I use background tasks but if the app is closed before the tasks are completed, they won’t be triggered after app restart. Maybe I will include my own resumeable function, but If hangfire can do it, it would be faster to implememt.
If your application is a server one that is placed near the database, why not? It is not tied to any application-level framework. But for client applications that are being installed on user machines it is definitely overkill.
Long Time ago, I started this thread. And now, 3 years later, I have my first implementation of Hangfire inside my client Application.
As documentation of Hangfire changed over years, I was able to integrate it easylie. Now, I have a windows-service for hosting hangfire server, a client application, also hosting a local version of hangfire and even a Dashboard implementation using owin. Now my dreams have become true
I hope you are still watching this thread. Please contact me, I need to do the same but everything is web based… I can pay you for your time and/or code.
On a windows server use Hangfire to have a single repository that replaces the Windows scheduled tasks. You can either use a windows service, or windows console, or windows form application as the server.
There are 2 things you need: 1: BackgroundJobServer to do the work, and 2: the Hangfire Dashboard to monitor it.
The dashboard is OWIN http hosted. If you user a windows service or console application to host the BackgroundJobServer you would access the dashboard via a browser window.
If you user a windows form application to host the BackgroundJobServer you can use a windows browser control in the form to view the dashboard from within the same application.
The BackgroundJobServer and dashboard need t be disposed when the form closes.
public partial class taskForm : Form
{
private BackgroundJobServer _server;
private IDisposable _dashServer;
public class OwinStartup
{
public void Configuration(IAppBuilder app)
{
var options = new DashboardOptions { AppPath = null };
app.UseHangfireDashboard("/hangfire", options);
}
}
public partial class Main : Form
{
private BackgroundJobServer _backgroundJobServer;
public Main()
{
InitializeComponent();
GlobalConfiguration.Configuration.UseInMemoryStorage();
_backgroundJobServer = new BackgroundJobServer();
BackgroundJob.Enqueue(() => Test());
}
}