HangfireIO / HangfireIO/Hangfire
Using Hangfire in .NET MAUi app
- Dominant language
- C#
- Stars
- 10.1k
- Forks
- 1.8k
- Avg merge
- 1h 19m
- Merged PRs (30d)
- 1
Description
Hi,
I have a class called SampleJob like this:
```
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Hosting;
namespace ContactsBackground
{
public class SampleJob : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
var timer = new Timer(async =>
{
try
{
Task.Run(() =>
{
var connectionString = "Server=xxxxx.database.windows.net;Database=xxxx;User Id=xxxxx;Password=xxxxx;";
var query = "EXEC insert_contact @person_id, @device_id, @prefix, @display_name, @first_name, @middle_name, @last_name, @nickname, @phonetic_first_name, @phonetic_middle_name, @phonetic_last_name, @suffix, @company, @job_title, @department, @birthday, @anniversary, @notes";
using (var connection = new SqlConnection(connectionString))
{
connection.Open();
using (var command = new SqlCommand(query, connection))
{
command.Parameters.Clear();
command.Parameters.AddWithValue("@person_id", "111");
command.Parameters.AddWithValue("@device_id", "222");
command.Parameters.AddWithValue("@prefix", "");
command.Parameters.AddWithValue("@display_name", "");
command.Parameters.AddWithValue("@first_name", "");
command.Parameters.AddWithValue("@middle_name", "");
command.Parameters.AddWithValue("@last_name", "");
command.Parameters.AddWithValue("@nickname", "");
command.Parameters.AddWithValue("@phonetic_first_name", "");
command.Parameters.AddWithValue("@phonetic_middle_name", "");
command.Parameters.AddWithValue("@phonetic_last_name", "");
command.Parameters.AddWithValue("@suffix", "");
command.Parameters.AddWithValue("@company", "");
command.Parameters.AddWithValue("@job_title", "");
command.Parameters.AddWithValue("@department", "");
command.Parameters.AddWithValue("@birthday", "");
command.Parameters.AddWithValue("@anniversary", "");
command.Parameters.AddWithValue("@notes", "");
command.ExecuteNonQuery();
}
}
});
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
}
}, null, TimeSpan.Zero, TimeSpan.FromMinutes(5));
}
}
}
}
```
How can I run this class as a background service in .NET MAUi? and what are the changes I need to make to the class to make it a Hangfire class?
Thanks,
Jassim
Contributor guide
Research direction
The issue names no repository files, tests, or entry points. Start by clarifying the .NET MAUI hosting context and reviewing the Hangfire integration guidance; done would be a maintainer-confirmed answer or documented example explaining whether this setup is supported and what registration changes are required.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend, mobile-dev
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 15/100