If you can change the
ProcessListings
method to do its work asynchronously, and return a
Task
, then this would be simple:
public async Task ProcessAsync(bool isForced)
{
var prevStatus = Status;
Status = SchedulerStatus.Processing;
await ProcessListingsAsync();
Status = prevStatus;
}
If you
can't change the
ProcessListings
method, then you'll need to run the method on a background thread - the simplest option would be to use
Task.Run[
^]:
public async Task ProcessAsync(bool isForced)
{
var prevStatus = Status;
Status = SchedulerStatus.Processing;
await Task.Run(ProcessListings);
Status = prevStatus;
}