473,761 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Synchronous events? (c++/cli)

9 New Member
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 3144
BahatiSiD
9 New Member
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
12146
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 events since I never saw it used anywhere in MSDN documentation/samples?! Or it will just break when I upgrade to .NET Framework 2.x in the coming years namespace MyNamespac public delegate void MyDel() public class MyBase public virtual...
5
9848
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 receives byte array data representing data structures at a rate of 30ms. On a thread seperate from that which Enqueues data to the buffer I have a high performance timer that Dequeues data from the custom buffer and sends it via a tcpClient...
2
1039
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 particular, what will happen if a class derives from two interfaces
3
1167
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, this thing raises events many times, however, you can modify data in the event args which is then passed back to the caller (I don't really understand how because the events are declared ByVal). Thats beside the point, but it appears to be...
1
1916
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 in Postgresql. I have a PHP application and when executing a query, I would like the queries to wait until the triggers have completed execution before returning to the application.
1
2058
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 perspective? interface class IMyClass { public: event MyDeleg^ MyEvent; }
1
1872
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 way to validate a form field by field like AJAX would do, but to keep it synchronous? i.e. one action, one validation. Thanks,
7
1468
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 actually very easy with the ATL wizard but I am lost when it comes to C++ .Net's events. Can anyone please point me to an example in VC++ .Net that allows me to then use the component in VB with the With Events keyword?
6
3018
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 signal my app to read the file. 2. My app also need o communicate this the driver using IOCTL. Can i do it in C#? can C# wait for events signaled from app written in C\C++ app running in on kernel and sends messages to device using
0
9377
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9925
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8814
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6640
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3913
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.