I think the problem is that you when you pass the event argument, you don't pass it is a value but as a reference. See
Parameter passing in C#[
^]
As you only create one instance of
MessageEventArgs me = new MessageEventArgs();
, you only have one place in the memory where your data is stored.
This means that when you change a member in that instance, that change will be reflected also in the event method.
The reason the sleep works is because you slow down the process enough for the values to be printed in the data grid before they are changed in the loop.
You should add one or more constructors with parameters to your
MessageEventArgs
class.
For example:
public MessageEventArgs(int weekNo, int dayNo)
{
this.WeekNo = weekNo;
this.DayNo = dayNo;
}
That way it is easy to create a new instance of the event argument for every message.
public void LongOperationMethod(BindingList<status> _statusData)
{
if (OnMessageSending != null)
{
for (int k = 0; k < 2; ++k)
{
for (int i = 0; i < 7; ++i)
{
for (int j = 0; j < 1000; ++j)
{
}
OnMessageSending(new MessageEventArgs(k, i));
}
}
OnMessageSending(new MessageEventArgs("Process completed successfully..."));
}
else
{
throw new ArgumentException("Event hasn`t been rised, so we cannot continue working.");
}
}
</status>