I am developing a C# class where I am allocated an array buffer, and each time an event fires, I am populating the next element in my array. So for example:
class MyClass
{
private int[] buffer = new int[10];
private int index = 0;
public void EventFired(object sender, IntEventArgs e)
{
buffer[index] = e.Integer;
index++;
}
}
If I have multiple events that are firing within rapid succession of one another, say every 0.5-1.0 ms, will EventFired
populate the array in the order which the events were fired? What if instead of storing one integer every time the event fires, I was storing 2,000 or 10,000 integers? Do I need to be worried about race conditions?
I'm not that familiar with the inner workings of C#/.NET so would love any advice on how to guarantee that we populate buffer
in the same order in which the events fired chronologically.