I have a service solution. (Console executable)
When the request comes from UI, it has to run a couple of operations.
First, based on the request that came from UI, it will fetch records from DB (The records can be in millions)
Once the records are available, there is a whole bunch of code that processes each record and do some publishing.
The UI will not wait for the whole operation to be completed.
UI should make a call and then the whole lengthy process should run in the background, meanwhile, the service will immediately send a response back to UI
I tried to put the whole long-running code (Fetching of records, processing and publishing) in a separate method.
I am doing like
Method()
{
try
{
BackgroundProcessing();
return true;
}
Catch (Exception ex)
{
// logging of exception
return false;
}
}
async void BackgroundProcessing()
{
await Task.Run( () =>
{
// Fetching of records
// Processing of records
});
}