'Process data asynchronously as it arrives from a server in order?

I'm connecting to an XMPP chat server using NetCoreServer. Everything is working as intended. Whenever the server sends a message I process it using a normal method processData(string data). The problem is that if the method takes longer than a specific amount of time, the server closes the connection.

I was thinking about executing the method asynchronously, but the problem is that messaging coming from the server could be split into parts. The method process data detects that, and if the message received is just one part of the entire message, it'll store it. Next time it's called appends the new message to the older one, checks if the new message completes it or if it needs to wait for the next message and so on, until it has a complete one. Then it'll continue with processing it, so if it's called asynchronously, the calls have to wait for previous ones before executing, without blocking the NetCoreServer's OnReceive.

I am thinking of adding a var task=new Task(() => { ProcessData(result); }); to a queue whenever new data from the server arrives, but I don't know how to chain their execution or how to proceed. Or I could store data in a queue as it arrives, and somehow trigger an event to call ProcessData whenever a new message is added into the queue. But I'm having the same problem aside from not knowing how, that events triggered should wait for the previous ones completion.

ProcessData looks something like this:

public Class DataProcessor
{
private string Buffer;
public void processData(string data)
{
    if(PartialData(data)) {
        Buffer+=data;
        return;
    }
    else //continue processing
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source