Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample to show how to execute Task on demand in .NET core 7 #361

Open
nssidhu opened this issue Feb 3, 2024 · 0 comments
Open

Sample to show how to execute Task on demand in .NET core 7 #361

nssidhu opened this issue Feb 3, 2024 · 0 comments

Comments

@nssidhu
Copy link

nssidhu commented Feb 3, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant