473,406 Members | 2,356 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,406 software developers and data experts.

Threading & Events

I have an object (Object1) that instantiates another class (Object2) in a
seperate thread. It must be in its own thread for an ActiveX control it
hosts to work.

From Object1 I can get to all the methods of the ActiveX control in Object2
which is fine. However, I need to get some information back from Object2 as
its state changes. How would I go about informing Object1 of events that
occur in the ActiveX control?

At the moment I'm rtying a workaround where I use a System.Timers.Timer to
periodically check the properties of the ActiveX control I'm interested in.
However the timer mechanism seems to be very unreliable. Sometimes the
'Elapsed event' doesnt occur at all, and sometimes it seems to occur in
quick succession before the code inside the 'Elapsed' event has finished
executing.

Help on either of these matters would be great but I think the first idea
will be better since as this project grows I may have to check too many
events in the timer.

--

Cheers,

elziko
Nov 20 '05 #1
2 1649

"elziko" <el****@NOTSPAMMINGyahoo.co.uk> wrote in message
news:ee**************@TK2MSFTNGP10.phx.gbl...
I have an object (Object1) that instantiates another class (Object2) in a
seperate thread. It must be in its own thread for an ActiveX control it
hosts to work.

From Object1 I can get to all the methods of the ActiveX control in Object2 which is fine. However, I need to get some information back from Object2 as its state changes. How would I go about informing Object1 of events that
occur in the ActiveX control?

At the moment I'm rtying a workaround where I use a System.Timers.Timer to
periodically check the properties of the ActiveX control I'm interested in.

No.... don't do that...
However the timer mechanism seems to be very unreliable. Sometimes the
'Elapsed event' doesnt occur at all, and sometimes it seems to occur in
quick succession before the code inside the 'Elapsed' event has finished
executing.

Help on either of these matters would be great but I think the first idea
will be better since as this project grows I may have to check too many
events in the timer.
You want to look into Asyncronous programming. There is a great great deal
of information on it at devx.com if you interested. But basically, you want
this separate thread to process, and raise an event saying, "I did
something" from the active X controls. now, you "could" directly link the
event to a method in your first thread using a delegate (because of the
separate threads you need to have a callback method, create yet another
delegate, it gets confusing, I'll help you more when you get there)

Or you could get a bit more advanced and use AsyncCallbacks... It doesn't
really matter in my opinion because they are essentially the same thing.
Raise event when I'm done, tell someone else. Async Callbacks are just more
often used in Multithreaded situations.

But never use timers to "poll" data. This can lead to all sorts of problem
(for example if your trying to SyncLock or Mutex a variable on a callback,
the timer just messes it up, because its still running... So data could get
corrupted if your process takes longer than your timer interval, see where
I'm going?) And many other problems can occur. =)

Hope it helps and let me know if you have more questions.

CJ
--

Cheers,

elziko

Nov 20 '05 #2
Hi, create an event in your Object2 class, and attach a handler to that
event in Object1:

Public Class Object2
Public Event MyStateChange As System.EventHandler
Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
4
by: Bardo | last post by:
Hi, I have a situation where I am capturing both a WMI event utilising the "ManagementEventWatcher" in the "System.Management" namespace, and a corresponding event ("EntryWritten") raised from...
6
by: MPH Computers | last post by:
Hi I am looking for some help on Threading and Critical Sections I have a main thread that controls an event the event handler creates a new thread for carrying out the work because the...
5
by: Andrew Lippitt | last post by:
What gaurantees are there in the way of which thread the events are called from. I've seen: Thread A Begin Thread B Begin Thread A End Thread A End That seems to indicate that Begin and End...
0
by: BenLeino | last post by:
Hi out there, I have a little problem with threading an event receiving. I have a custom Class (DLL) that raises Events. When I run the Instance without threading it works fine. When I do...
13
by: Bob | last post by:
My WinForms app runs on the single default thread, and uses a single SqlConnection object for all queries. I need to use one or more timers to periodically execute some of them. My own testing...
12
by: Aidal | last post by:
Hi NG. I'm creating a little app. that has to use a 3rd party API. The functions in this API has no return value but trigger events like OK or NOT OK with event args. Where I need to use this...
5
by: Spam Catcher | last post by:
Hi all When .NET fires and event, does the event handler execute under a new thread, or does it execute under the primary application thread? Basically if I have events firing, do the event...
5
by: JasonX | last post by:
Im having problems with my program, in that if I close the main form while my new thread is doing work which involves writing to the main form, then I get an error about a disposed object. To...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.