-
Custom Events and Event Handlers
I'm new to C++ programming (but coming from a c-sharp) and have been working on translating some of the dlls that I've written in the past to C++.
Anyway, one of the dlls that I'm writing uses event notifications to let the user know when database calls (amongst other things) are complete. I've been looking through some of the online tutorials and find very little on how to port my c-sharp events to C++.
Any suggestions, thoughts or hints would be great!
-
not knowing anything at all about what you did, all I can do is give generic answers. Basically, the raw language is unaware of events -- of course -- the language is also unaware of the concept of a database too, and only vaguely aware of the CPU and OS with some fairly generic and crude interfaces to those.
However the extended language, using standard libraries, makes such things possible.
My suggestion here is to use threading, such as the standard p-threads library or if you are in windows, the built in threading library of visual studio is pretty good.
basically, by wrapping a database call in a thread you can detect if that call is done (the thread returns a value, or can flip a boolean, invoke a function, or whatever you like), effectively trapping the 'done' event. If something needs to happen immediately after the DB call is done, you can do it too, just put it after the DB call inside the thread function body, depending on what you need to do.
Other event handling is done through the OS and related OS libraries, such as keyboard events, system shutdown (broadcast internally by the OS, you listen for it if you care), or the like. Still other events are hardware related and quite complex to handle.
-
Thanks for the reply.
I had thought about using threading to make my database call asynchronous (sp?). My thought being that users could continue to work within the program without locking up the program each time they execute a long running queries etc.
I've been looking at using callbacks to handle this sort of notification.
-
If the database tools you use support callbacks that will work just fine. Threading will also work just fine, as you said it prevents lockup for long periods. Again, every thread library I have ever seen has a way that can be polled to determine if a thread is done yet, or you can have the thread function itself do something when the database call returns, lots of ways to handle it.
Similar Threads
-
By it-bergmann in forum ASP.NET
Replies: 2
Last Post: 03-27-2008, 05:32 PM
-
By me_code2004 in forum .NET
Replies: 1
Last Post: 06-07-2006, 08:52 PM
-
By Prometheus in forum Java
Replies: 0
Last Post: 02-20-2005, 01:06 PM
-
By Florian Fankhauser in forum .NET
Replies: 0
Last Post: 07-03-2002, 03:31 AM
-
By Sachin in forum VB Classic
Replies: 8
Last Post: 09-09-2001, 11:29 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks