473,799 Members | 3,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

COM Interop and ManualResetEVen ts

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
manualResetEven t 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 1888
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
ManualResetEven t.

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********@dir con.co.uk> wrote in message
news:#N******** ******@tk2msftn gp13.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
manualResetEven t 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
2363
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' Application. ----------------------------------------------------------- --------------------- Configuration Error Description: An error occurred during the processing of a
0
1570
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. ----------------------------------------------------------- --------------------- Configuration Error Description: An error occurred during the processing of a configuration file required to service this request.
0
2292
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 about the global assembly cache (GAC) and primary interop assemblies (PIA) and so forth, and did all the recommendations, in terms of tweeking Office, installing the .NET Office stuff for framework 1.1, etc. I got it to the point where it compiles ok,...
0
2794
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 interop-filenames to be interop.<NameOfCOMDLL>.dll I now make the first interop file tlbimp COM1.dll /out:interop.COM1.dll /namespace:COM1
1
1999
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, this layer manage the underlying COM Objects and upon request, provide a pointer to those objects to the 'API Consumer', following is an illustration of the system: API Consumer ( Native C++/C# ) || ******************************************* * ...
8
3426
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 added. Converting the type library to a .Net assembly failed. A depended type library 'CDO' could not be converted to a .NET assembly. A dependent type library 'ADODB' could not be converted to a .NET assembly. Item has already been added." ...
7
10964
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 this screen below. Please help, thanks in advance... Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify...
2
7305
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 "Array index out of bounds". Microsoft.Office.Interop.Outlook._Application olApp = new Microsoft.Office.Interop.Outlook.ApplicationClass(); Microsoft.Office.Interop.Outlook._NameSpace olNs = olApp.GetNamespace("MAPI");
1
2872
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 and server (Exchange server mail box) to connect and then save the mailitems(from Inbox or any other folder) based on a filter to a*.msg file. I want to achieve this using only one Interop dll if this is possible. Tried so far:
0
2060
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 fine. Help! T Server Error in '/VT.Users' Application. -------------------------------------------------------------------------------- Configuration Error
0
9688
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, 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...
0
9546
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,...
0
10491
Oralloy
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...
1
10247
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,...
0
9079
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, 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...
1
7571
isladogs
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...
0
5467
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...
0
5593
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.