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

COM Interop and ManualResetEVents

I raised this a few days ago and Dmitriy helped, but there's been a lot of
posts under the bridge since then so I thought I'd start afresh.

Basically, I have a COM Dll written in C++ (6). It's job is to create DVD
Images which it does nicely. It runs Asynchronously. That is (once all the
information is provided) it starts its own thread and raises events as
things develop.

The events are marshalled through a hidden window to so that they aways call
back on the thread which created the object. This is a requirement for them
to run in an STA like VBs.

I've added this to my c# project and hooked the events. When I want to
create the image I call the method on my COM object and the wait for a
manualResetEvent to be set. This should be done by the com event handler,
but it does not.

When the WaitFor times out all the events that should have happened suddenly
come through (by this time the thread has returned control the Windows Forms
test program).

If I use a loop with Sleeps the same thing happens.

I've tried with the the thread marked as STA and MTA - no difference. I've
put the call to the main com method on a separate thread. Still doesn't
work.

The only way I can get it to work is by returning control to the UI.

Now the good book says in 'Managed and Unmanaged Threading in Microsoft
Windows'

That WaitHandle (and it's descendents) ... all these managed blocking
operations will correctly pump messages in your apartment while your thread
is blocked.

This seems not to be the case.

Dmitry suggesting putting the Event handlers on another thread, but to be
truthful I dont see how I can do that without some sort of blocking which
seems to stop the events being received!

I also wonder if it's something to do with the events being forced to come
back on the thread which created them. Perhaps this is NOT the thread as it
appears in c#? (The Com object is marked as both. I suppose I could try
de-marshalling the events and see if that helps - will break it in VB
though!)

This system will eventually sit inside a service, so the obvious answer of
writing it with Timers and state variables and a Windows Form is not ideal.

Any ideas (and thankyou)?

Iain
Nov 15 '05 #1
1 1869
Well. For anyone that wants to know, demarshalling the events in the COM
object allowed the events to be seen during the WaitOne of the
ManualResetEvent.

Basically, in the COM dll the events were (largely) raised on a seperate
thread than the one which created the object. In order to work with VB
(which is single threaded) you have to Post a Windows Message to a hidden
window. This is picked up by the Message Pump of the hidden window (which
runs on the main thread) and you then raise the event.

So I've taken that bit out. Now I raise the event directly in the thread
which causes the event.

Now these events are received during the Wait state of the C# program and it
does the setting of the events and it all works nicely.

It works with the c# thread marked as MTA and it works with the c# thread
marked as MTA.

If any MS support people read this thread, it seems to me that this is an
appropriate subject for a knowledge base article.

OH - and I'd LOVE to know why this happens!

This sort of stuff is NOT obvious - though I must admit that mutlithreaded
com objects which raise events, are meant for VB and now want to be used in
c# are *probably* not around in their masses.

Iain
"Iain" <id********@dircon.co.uk> wrote in message
news:#N**************@tk2msftngp13.phx.gbl...
I raised this a few days ago and Dmitriy helped, but there's been a lot of
posts under the bridge since then so I thought I'd start afresh.

Basically, I have a COM Dll written in C++ (6). It's job is to create DVD
Images which it does nicely. It runs Asynchronously. That is (once all the information is provided) it starts its own thread and raises events as
things develop.

The events are marshalled through a hidden window to so that they aways call back on the thread which created the object. This is a requirement for them to run in an STA like VBs.

I've added this to my c# project and hooked the events. When I want to
create the image I call the method on my COM object and the wait for a
manualResetEvent to be set. This should be done by the com event handler,
but it does not.

When the WaitFor times out all the events that should have happened suddenly come through (by this time the thread has returned control the Windows Forms test program).

If I use a loop with Sleeps the same thing happens.

I've tried with the the thread marked as STA and MTA - no difference. I've put the call to the main com method on a separate thread. Still doesn't
work.

The only way I can get it to work is by returning control to the UI.

Now the good book says in 'Managed and Unmanaged Threading in Microsoft
Windows'

That WaitHandle (and it's descendents) ... all these managed blocking
operations will correctly pump messages in your apartment while your thread is blocked.

This seems not to be the case.

Dmitry suggesting putting the Event handlers on another thread, but to be
truthful I dont see how I can do that without some sort of blocking which
seems to stop the events being received!

I also wonder if it's something to do with the events being forced to come
back on the thread which created them. Perhaps this is NOT the thread as it appears in c#? (The Com object is marked as both. I suppose I could try
de-marshalling the events and see if that helps - will break it in VB
though!)

This system will eventually sit inside a service, so the obvious answer of
writing it with Timers and state variables and a Windows Form is not ideal.
Any ideas (and thankyou)?

Iain

Nov 15 '05 #2

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

Similar topics

0
by: roy | last post by:
I try to call com written in VB 6.0. When I use VS.net Studio to do the debuging, some time it works fine, some time I got the following message: Server Error in '/GISOnlineReservation'...
0
by: roy | last post by:
I try to call com written in VB 6.0., some time it works fine, some time I got the following message: Server Error in '/GISOnlineReservation' Application....
0
by: keefah | last post by:
Hi, I'm writing a C# web app that uses Outlook to send email. I use a reference to the Microsoft Outlook 11.0 Object Library, but it's giving me problems. I tracked down some stuff on the Net...
0
by: lacour | last post by:
I can't seem to figure out the difference between adding a COM dll reference in VS2003 and by using TLBIMP. I have a COM dll that references another COM dll, and I want the syntax of my...
1
by: Nadav | last post by:
Hi, Introduction *************** I have a system build of a collection of 'Native COM objects' and '.NET COM interop' objects, all of the COM objects are managed through a 'Native COM' layer,...
8
by: Rob Edwards | last post by:
When trying to add the Microsoft CDO for Exchange Management Library (aka CDOEXM.dll) I receive the following message: "A reference to 'Microsoft CDO for Exchange Management Library' could not be...
7
by: R Reyes | last post by:
Can someone please explain to me why I can't get the MS Word Interop assembly to work in my VS2005 project? I'm trying to manipulate MS Word from my Web Form application and I can't get passed...
2
by: JC | last post by:
Anybody knows what problem has this code? I think, in the Garbage Collector? You know the Solution? The program in the test's case, whit 350 contacts, run OK before number 86. The error is a...
1
by: allbelonging | last post by:
C#.Net Outlook 2003 automation (programmatically) with Office.Interop.Outlook Problem: I have my outlook 2003 configured with multiple mailbox on my local machine. I want to specify the mailbox...
0
by: Tina | last post by:
I've gotten this before where it says there is a problem with Interop.MSDASC but I can't remember what causes this. This is a 1.1 app I'm trying to debug in vs2005. It was running yesterday just...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
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...

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.