I have a C# class that wraps a UDP socket to make receiving and processing network data easier.
Whenever data is received, an event is fired with the data passed as an argument:
public event Action<byte[]> DataReceived = delegate(byte[] data) { };
I receive the data and fire the event like so:
while (socket.IsBound)
{
var buffer = new byte[MaximumDataLength];
socket.Receive(buffer);
DataReceived(buffer);
}
My understanding is that the same array instance is passed to each event handler.
Could this cause issues later on if one of those handlers modifys the array before the other handlers get to process it?
If so, what are some good ways to remedy this?