473,387 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Synchronous events? (c++/cli)

Hello!

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
  1. public: delegate void CpuStepEventHandler(Object^ sender, CpuStepEventArgs^ e);
  2.     public: event CpuStepEventHandler^ CpuStepEvent;
  3.     protected: virtual void OnCpuStepEvent(CpuStepEventArgs^ e) {
  4.                    //if(CpuStepEvent != nullptr)
  5.                    CpuStepEvent(this, e);
  6.                }  
I'm firing it like this:
Expand|Select|Wrap|Line Numbers
  1. CpuStepEventArgs^ step = gcnew CpuStepEventArgs();
  2. OnCpuStepEvent(step);
  3. //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.
Apr 14 '09 #1
1 3124
Got it!

When you think about it (which I was apparently not able to do at five AM) there had to be something going on in the handler which is not immediately done - i.e. drawing the new row in the DataGridView.

The 'secret' was the Refresh() method of the dgv which forces it to redraw immediately.

My little cpu is now, of course, painfully slow, but that's kind of the whole point - to be able to SEE it work.

All this drawing makes my GUI pretty unresponsive so I will probably have to go the dreaded threading route. Just a heads up, 'cos I'm bound to have same more lame questions in the wee hours of the morning.

Thanks to anyone that read this!
Apr 14 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: JPRoot | last post by:
Hi I use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using...
5
by: Jeff Weber | last post by:
First, my question: Should I use Write or BeginWrite (sync or async) to stream data to my clients over a TCPClient connection. Details: On the server I have a custom circular data buffer that...
2
by: Chris | last post by:
Hi, I'd like to know if it makes sense to define an event in an interface. Something like: public interface class MyInterface1 { event PropertyChangedEventHandler^ PropertyChanged; } ; In...
3
by: CJ Taylor | last post by:
I don't know how to do this persay, but maybe someone could give me a little guidance. I will start with an example, if you've ever heard of ComponentOne they have a tool called DataObjects,...
1
by: Shri Shrikumar | last post by:
Hi All, I am not sure if this is the right list for this question, so if its not, I would appreciate a pointer in the right direction. Anyways, I would like to know if triggers are synchronous...
1
by: Grafix | last post by:
All - I am facing couple of problems with events in CLI C++. If i have an interface that declares few events, and a ref class implements that interface, should it do anything extra from events...
1
by: AECL_DEV | last post by:
Hello Everyone, Ive seen alot of people saying that the best way to AJAX Validate a form is through the submit button, because validation should be synchronous. Im wondering, is there any good...
7
by: Bruce | last post by:
I have a DotNet C++ class that I would like to fire an event to then be used by VB.Net using the With Events keyword. I have experience creating connection point events for ActiveX controls, it is...
6
by: Eran.Yasso | last post by:
Hi all, I need to write a GUI app which do the followings: 1. My app waits for events from other app(actually this is a network adapter driver) running in kernel. The driver writes to file and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.