473,396 Members | 1,995 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,396 software developers and data experts.

Addhandler in a Multithreading class and the events raised in seperate threads, how to get to the caller thread?

Hello,

I have a problem and I can't get the solution for it :(

I have a com dll, which i imported as a reference. The com object is
part of a class which is multithreaded and will create seperate objects
which we can and must control. On these com objects I added the events
via AddHandler. This is working great, I can see that my threads are
raising events through the com object.

Now the following problem arises: These events will run in a seperate
process and will not pass the correct objects (out of the caller
threads), so I can not see wich event is raised by which thread. When I
add data to a global var, it will be overwritten by the last call we
have made, so this is not accurate too. Can I make connection to the
caller thread (on the event which has been called)? Can you point me in
the right direction, I think it's possible, but...

ohhh, I've tried to call the com object with the WithEvents statement,
but this will overwrite the eventhandler....

Thanks in advace!!

Daan

Jul 29 '06 #1
3 2254
Can anybody please help me with this issue?

da**@dnc.nu wrote:
Hello,

I have a problem and I can't get the solution for it :(

I have a com dll, which i imported as a reference. The com object is
part of a class which is multithreaded and will create seperate objects
which we can and must control. On these com objects I added the events
via AddHandler. This is working great, I can see that my threads are
raising events through the com object.

Now the following problem arises: These events will run in a seperate
process and will not pass the correct objects (out of the caller
threads), so I can not see wich event is raised by which thread. When I
add data to a global var, it will be overwritten by the last call we
have made, so this is not accurate too. Can I make connection to the
caller thread (on the event which has been called)? Can you point me in
the right direction, I think it's possible, but...

ohhh, I've tried to call the com object with the WithEvents statement,
but this will overwrite the eventhandler....

Thanks in advace!!

Daan
Aug 1 '06 #2
da**@dnc.nu wrote:
Can anybody please help me with this issue?
Well, I'll give it a go, but this isn't really my area...
>
da**@dnc.nu wrote:
>Hello,

I have a problem and I can't get the solution for it :(

I have a com dll, which i imported as a reference. The com object is
part of a class which is multithreaded and will create seperate objects
which we can and must control. On these com objects I added the events
via AddHandler. This is working great, I can see that my threads are
raising events through the com object.

Now the following problem arises: These events will run in a seperate
process and will not pass the correct objects (out of the caller
threads), so I can not see wich event is raised by which thread. When I
add data to a global var, it will be overwritten by the last call we
have made, so this is not accurate too. Can I make connection to the
caller thread (on the event which has been called)? Can you point me in
the right direction, I think it's possible, but...
I don't know how much this is an interop problem and how much it is a
multi-threading problem. Therefore I can only suggest fixing the
threading issues: have locks for each object that is shared or
accessible from more than one threads, and religiously SyncLock before
doing anything to these objects. Then try again, and see if you still
get problems. If you do, it's something on the interop side. If you
don't, then great, we've just done a practical demonstration of the
importance of controlling access to contended resources.

Tell you what, maybe you could mock up a .NET component that exposes the
same behavior as the com component, and plug that in, to see if it's
interop or threading that's the problem?

--
Larry Lard
la*******@googlemail.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version
Aug 1 '06 #3
Hi Larry,

Synclock would be a problem because of the asynchronous way events are
raised by the com object... We synclock the first object, the events
raised knows it has something to do with the first lock object, we
release the synclock, than the second object is created with a
synclock. Now the issue rise, what if when events are fired for the
first object, it will retrieve the information for the lock, and the
wrong information is handled

I think I can code to the solution when I know how to get to the caller
thread, then I can receive the correct object.

Thanks!

Larry Lard wrote:
da**@dnc.nu wrote:
Can anybody please help me with this issue?

Well, I'll give it a go, but this isn't really my area...

da**@dnc.nu wrote:
Hello,

I have a problem and I can't get the solution for it :(

I have a com dll, which i imported as a reference. The com object is
part of a class which is multithreaded and will create seperate objects
which we can and must control. On these com objects I added the events
via AddHandler. This is working great, I can see that my threads are
raising events through the com object.

Now the following problem arises: These events will run in a seperate
process and will not pass the correct objects (out of the caller
threads), so I can not see wich event is raised by which thread. When I
add data to a global var, it will be overwritten by the last call we
have made, so this is not accurate too. Can I make connection to the
caller thread (on the event which has been called)? Can you point me in
the right direction, I think it's possible, but...

I don't know how much this is an interop problem and how much it is a
multi-threading problem. Therefore I can only suggest fixing the
threading issues: have locks for each object that is shared or
accessible from more than one threads, and religiously SyncLock before
doing anything to these objects. Then try again, and see if you still
get problems. If you do, it's something on the interop side. If you
don't, then great, we've just done a practical demonstration of the
importance of controlling access to contended resources.

Tell you what, maybe you could mock up a .NET component that exposes the
same behavior as the com component, and plug that in, to see if it's
interop or threading that's the problem?

--
Larry Lard
la*******@googlemail.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version
Aug 1 '06 #4

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

Similar topics

9
by: GM | last post by:
Hi, My application has a need to cache a number of shared reference lists containing basic business objects. In order to improve performance these lists are fetched and updated in the...
1
by: dixp | last post by:
I'm new to writing multithreaded apps and I have a design question. I have a winforms app and a class which has a method that does processing which is time intensive. I want the user to be able...
16
by: Robert Zurer | last post by:
Can anyone suggest the best book or part of a book on this subject. I'm looking for an in-depth treatment with examples in C# TIA Robert Zurer robert@zurer.com
3
by: Stampede | last post by:
Hi, I want to use the FileSystemWatcher in a Windows Service. I read an article, where the author created the FileSystemWatcher object in a seperate thread and when the event is fired, he started...
1
by: Muralidharan Ramakrishnan | last post by:
Hi, I am trying to run a complex report in my asp.net application. The method which executes the report runs in a SEPERATE thread from threadpool other than the main application thread. The...
20
by: Charles Law | last post by:
Consider the following scenario: A data packet is sent out of a serial port and a return packet is expected a short time later. The application sending the packet needs to send another packet...
6
by: Michael | last post by:
I have an application that monitoring some directories. When new file arrives my application importing that file into database (very long process) I want to rewrite this application to multithread...
2
by: Pradnya Patil | last post by:
hi , I am trying to draw ' html div-tag ' on the screen which will resemble a rectangle through vb.net code. I want it to be drawn faster...so I introduced multithreading using Threadpool. I...
6
by: dgleeson3 | last post by:
Hello All Im having lots of fun with window handles and invoke. The code started off in a single class. Main thread set up a worker thread and the worker thread updated the progress bar on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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
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...
0
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...
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.