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.T imer 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 2 1660
"elziko" <el****@NOTSPAM MINGyahoo.co.uk > wrote in message
news:ee******** ******@TK2MSFTN GP10.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.T imer 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
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.EventHan dler This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 the moment. I'd be *very* grateful if people with any interest in
multi-threading would read it (even just bits of it - it's somewhat
long to go through the whole thing!) to check for accuracy,
effectiveness of examples, etc.
Feel free to mail...
|
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 the "EventLog" object in
the "System.Diagnostics" namespace.
When a certain event occurrs, both a WMI event is raised, and an event log
entry is written.
The problem I have is that I need to capture both events and somehow
correlate which WMI...
|
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 work may not be completed before the event is triggered again
I am trying to add critical sections round the producer & consumer parts of
|
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 can't be assumed to be called from the same thread, but can I assume that the Begin will happen on the same thread that executes the request?
|
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 threading no Events are received.
Code:
| |
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 indicates that the forms
timer does not operate on its own thread and will not cause a query to be
sent to use the single SqlConnection while another is being executed from
the handling of other events. Is that right? I just want to be 100% sure...
|
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 API I must have a synchrone modul so I need to
force a synchrone look to this asynchrone model of the API.
I was thinking this would call for some waiting for events and since I
|
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 handlers themselves need to
spawn need threads, or can I safely assume the event handler is already
running under a new thread?
|
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 fix this, i have added an event, with the aim the main form
subscribes to the event when it is created and unsubscribes as soon as
its closed. This approach however has not fixed the problem. When the
event is raised, it writes to the form using a...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |