Skip to content

Async in scheduled jobs #3157

Answered by sbwalker
avazon asked this question in Q&A
Aug 17, 2023 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

@avazon The HostedServiceBase would need to include support for an async method (note the change from abstract to virtual methods which is a non-breaking change):

ie.

    // one of the following methods must be overridden
    public virtual string ExecuteJob(IServiceProvider provider)
    {
        return "";
    }

    public virtual Task<string> ExecuteJobAsync(IServiceProvider provider)
    {
        return Task.FromResult(string.Empty);
    }

and in the ExecuteAsync() method:

    notes += ExecuteJob(scope.ServiceProvider);
    notes += await ExecuteJobAsync(scope.ServiceProvider);

I think async support is a good idea for scheduled jobs

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by avazon
Comment options

You must be logged in to vote
1 reply
@avazon
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants