I have a class instance that fires events and they are handled in a form.
I believe this kind of event is called trivial:
Expand|Select|Wrap|Line Numbers
- public: delegate void CpuStepEventHandler(Object^ sender, CpuStepEventArgs^ e);
- public: event CpuStepEventHandler^ CpuStepEvent;
- protected: virtual void OnCpuStepEvent(CpuStepEventArgs^ e) {
- //if(CpuStepEvent != nullptr)
- CpuStepEvent(this, e);
- }
Expand|Select|Wrap|Line Numbers
- CpuStepEventArgs^ step = gcnew CpuStepEventArgs();
- OnCpuStepEvent(step);
- //next line
The problem is that the next line seems to be executed before the handler finishes it's work!
And bizarrely, I sometimes require the EventArgs in a function that fired the event (ie. in that next line) and it seems to hold the changes made by the handler just fine!
I used a StopWatch to measure the ticks before and after the firing of the event and at the start and end of the handler function. And the figures vary greatly! And they shouldn’t if the event is synchronous right?
As you can probably guess from the code, the app I’m making is a little cpu emulator. The class that models the cpu fires the event every time it finishes a step (instruction). The handler in a form uses the EventArgs to add a row with the step information to a DataGridView control. If the cpu takes too many steps to finish the rows don't show until it's done, and all you can see while it's working is that the vertical scroll of the grid is getting thinner - indicating that the rows are being added. I just can't see 'em until it's all done! I've tried using Invalidate() on the form, grid and the new row itself w/o success.
I'm most probably doing something wrong, but I'm pretty new at this 'event driven' malarkey so I'm stumped. Please help? Thanks in advance!
PS. I don't know if it matters, but I'm actually creating the EventArgs in one function and pass them to another one that does the actual firing of the event.
PPS. 'Synchronous' means that everything is nice and sequential right? I might have gotten the term wrong, but I hope it's clear what I'm after.