Skip to content

Instantly share code, notes, and snippets.

@EngRajabi
Last active September 17, 2020 12:23
Show Gist options
  • Save EngRajabi/a96388485fc1aff19d499a70fe14aa82 to your computer and use it in GitHub Desktop.
Save EngRajabi/a96388485fc1aff19d499a70fe14aa82 to your computer and use it in GitHub Desktop.
UseWorkers.cs
//fill object
var smsContext = new SmsReq();
var action = _workers.AddWork<SmsReq>(SendSms);
action.Post(smsContext);
private async Task SendSms(SmsReq smsReq)
{
try
{
using var scope = _serviceProvider.CreateScope();
var service = scope.ServiceProvider.GetRequiredService<ISmsSender>();
await service.Send(smsReq);
}
catch (Exception e)
{
_logger.LogError(e, e.Message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment