Describe the solution you'd like
I am using Blazor server .NET 7
My requirement is to run the long running process in the background thread.
This long running code should only run once and only when user submits the form by clicking the button.
Here is sample of my code.
public class SubmitBackgroundTask : IInvocable
{
private readonly ILogger _logger;
private readonly string _storyID;
IDbContextFactory _DbFactory;
LexIADBContext _dbContext;
public SubmitBackgroundTask(ILogger logger, IDbContextFactory DbFactory, string StoryId)
{
_DbFactory = DbFactory;
_logger = logger;
_storyID = StoryId;
}
public async Task Invoke()
{
using var _dbContext = await _DbFactory.CreateDbContextAsync();
_logger.LogInformation($"Invocable task running. StoryId is {_storyID}");
await Task.CompletedTask;
}
}
Describe alternatives you've considered
I tried to use DI, but i am getting run time error for my second which i cannot provide during registration in program.cs, that userID string parameter is only available when user Click the submit button on index page
Describe the solution you'd like I am using Blazor server .NET 7 My requirement is to run the long running process in the background thread. This long running code should only run once and only when user submits the form by clicking the button.
Here is sample of my code.
public class SubmitBackgroundTask : IInvocable { private readonly ILogger _logger;
private readonly string _storyID;
IDbContextFactory _DbFactory;
LexIADBContext _dbContext;
public SubmitBackgroundTask(ILogger logger, IDbContextFactory DbFactory, string StoryId)
{
_DbFactory = DbFactory;
_logger = logger;
_storyID = StoryId;
}
public async Task Invoke()
{
using var _dbContext = await _DbFactory.CreateDbContextAsync();
_logger.LogInformation($"Invocable task running. StoryId is {_storyID}");
await Task.CompletedTask;
}
}
Describe alternatives you've considered
I tried to use DI, but i am getting run time error for my second which i cannot provide during registration in program.cs, that userID string parameter is only available when user Click the submit button on index page