Skip to content

How about long running work that is done using an async method #76

Open
@alizahid4004

Description

For something like the following:

public class QueueProcessor
{
    private readonly BlockingCollection _messageQueue = new BlockingCollection();
    
    public void StartProcessing()
    {
        //Start background processing here. What's the best approach?
    }

    public void Enqueue(Message message)
    {
        _messageQueue.Add(message);
    }
    
    private async Task ProcessQueue() //notice the async Task here
    {
        foreach (var item in _messageQueue.GetConsumingEnumerable())
        {
             await ProcessItem(item).ConfigureAwait(false);
        }
    }
    
    private async Task ProcessItem(Message message) { }
}

What is the best approach of executing the long running work in the background? I have looked everywhere and I've found a lot of contradicting advice on this.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions