I've got a (VC++ 6.0) com object which does something asynchronously (writes
a DVD image, actually).
It rasies COM events to indicate progress, including completion.
I've got this running in a c# application, with the events coming up and
being caught (The idea is to use this to Set a ManualResetEvent which will
alow the rest of the processign to happen).
However, when I put an event after the call to start the async process off,
the events seem never to be caught.
When the WaitOne times out, I get a whole swathe of debug prints from the
COM dll, but the Debug.WriteLine from the (COM) event handler are never
called.
Clearly it's some threading / synchronisation issue, but I've not found
anything obviously relevant in the docs or through google.
Can any one help, please?
Iain 6 3063
Hi,
As your application is most likely marked with [STAThread], the events
raised by the COM object are handled on the single UI thread your
application has. Once you block the UI thread with WaitOne(), it will never
be able to process further events from the COM object.
--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE
"Iain" <id********@dircon.co.uk> wrote in message
news:Oe**************@tk2msftngp13.phx.gbl... I've got a (VC++ 6.0) com object which does something asynchronously
(writes a DVD image, actually).
It rasies COM events to indicate progress, including completion.
I've got this running in a c# application, with the events coming up and being caught (The idea is to use this to Set a ManualResetEvent which will alow the rest of the processign to happen).
However, when I put an event after the call to start the async process
off, the events seem never to be caught.
When the WaitOne times out, I get a whole swathe of debug prints from the COM dll, but the Debug.WriteLine from the (COM) event handler are never called.
Clearly it's some threading / synchronisation issue, but I've not found anything obviously relevant in the docs or through google.
Can any one help, please?
Iain
Thanks Dmitriy.
But what do I DO?
Obviously the com dll is mutlithreaded ('both'). I've been trying to find
something on this attribute in the docs but haven't hit anything I find
particularly useful. Nor with MTAThread which is what I presume I should
use.
The test program is a windows forms program and I've changed the attribute
on Main() to [MTAThread] which has made no difference. I've also changed
the attributes of the methods that seem relevant (and the event handler) in
my class that does all the work - also to no avail.
Lastly, I've replaced the wait with a sleep loop. which I would have
thought would stand some chance of working. but no.
Sorry. still stuck.
Iain
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:OQ**************@TK2MSFTNGP09.phx.gbl... Hi,
As your application is most likely marked with [STAThread], the events raised by the COM object are handled on the single UI thread your application has. Once you block the UI thread with WaitOne(), it will
never be able to process further events from the COM object.
-- Dmitriy Lapshin [C# / .NET MVP] X-Unity Test Studio http://x-unity.miik.com.ua/teststudio.aspx Bring the power of unit testing to VS .NET IDE
I've put a bit of debug code just before the creation of the Com object (and
after the invocation of thee method in the Com object) and the Thread at
those points is MTA.
So it looks like the problem is elsewhere.
The underlying COM object has been coded to work in VB 6 which means that
the events are raised from the main thread (basically the worker thread
sends the event information into a Windows Message loop owned by COM Object.
when this is received it raises the event). So the events are effectively
marshalled on to the initiating thread.
The thread which is doing the writing does not seem visible in the .NET IDE,
however it does continue to operate even after I break the c# stuff.
Iain
"Iain" <id********@dircon.co.uk> wrote in message
news:uG**************@tk2msftngp13.phx.gbl... Thanks Dmitriy.
But what do I DO?
Obviously the com dll is mutlithreaded ('both'). I've been trying to find something on this attribute in the docs but haven't hit anything I find particularly useful. Nor with MTAThread which is what I presume I should use.
The test program is a windows forms program and I've changed the attribute on Main() to [MTAThread] which has made no difference. I've also changed the attributes of the methods that seem relevant (and the event handler)
in my class that does all the work - also to no avail.
Lastly, I've replaced the wait with a sleep loop. which I would have thought would stand some chance of working. but no.
Sorry. still stuck.
Iain
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote in message news:OQ**************@TK2MSFTNGP09.phx.gbl... Hi,
As your application is most likely marked with [STAThread], the events raised by the COM object are handled on the single UI thread your application has. Once you block the UI thread with WaitOne(), it will never be able to process further events from the COM object.
-- Dmitriy Lapshin [C# / .NET MVP] X-Unity Test Studio http://x-unity.miik.com.ua/teststudio.aspx Bring the power of unit testing to VS .NET IDE
You can try the following. In the .NET application, launch a separate thread
that would only wait for an event. When the event is set, this thread would
notify the main thread by invoking some method through Form.Invoke() and
immediately exit.
--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE
"Iain" <id********@dircon.co.uk> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... I've put a bit of debug code just before the creation of the Com object
(and after the invocation of thee method in the Com object) and the Thread at those points is MTA.
So it looks like the problem is elsewhere.
The underlying COM object has been coded to work in VB 6 which means that the events are raised from the main thread (basically the worker thread sends the event information into a Windows Message loop owned by COM
Object. when this is received it raises the event). So the events are effectively marshalled on to the initiating thread.
The thread which is doing the writing does not seem visible in the .NET
IDE, however it does continue to operate even after I break the c# stuff.
Iain "Iain" <id********@dircon.co.uk> wrote in message news:uG**************@tk2msftngp13.phx.gbl... Thanks Dmitriy.
But what do I DO?
Obviously the com dll is mutlithreaded ('both'). I've been trying to
find something on this attribute in the docs but haven't hit anything I find particularly useful. Nor with MTAThread which is what I presume I
should use.
The test program is a windows forms program and I've changed the
attribute on Main() to [MTAThread] which has made no difference. I've also
changed the attributes of the methods that seem relevant (and the event handler) in my class that does all the work - also to no avail.
Lastly, I've replaced the wait with a sleep loop. which I would have thought would stand some chance of working. but no.
Sorry. still stuck.
Iain
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com>
wrote in message news:OQ**************@TK2MSFTNGP09.phx.gbl... Hi,
As your application is most likely marked with [STAThread], the events raised by the COM object are handled on the single UI thread your application has. Once you block the UI thread with WaitOne(), it will never be able to process further events from the COM object.
-- Dmitriy Lapshin [C# / .NET MVP] X-Unity Test Studio http://x-unity.miik.com.ua/teststudio.aspx Bring the power of unit testing to VS .NET IDE
Hmm. I'm trying to get my head round this (sorry, I've taken some time out
to do some higher level stuff, now back to the detail).
Basically, this will end up as a server process - possibly a service, so I
can't rely on UI level stuff like timers of Form.Invoke.
I've taken the waitforone out as an experiment and also the stuff that's
meant to follow afterwards (leaving the code to return to the test UI) and
the events come through fine.
I've tried setting the process of on another thread, but that failed.
Reasonably enough as I guess the thread that could receive the messages is
still locked and therefore will not peek the equivalent of a message loop
(which seems to be the essential problem) - I am by the way, reasonbly
convinced that I could have done this in unmanaged C++ 6 without this class
of problem, though in truth I haven't tried it.
I can't actually see any way of setting of a thread which just waits for the
events. If I block it, it wont get the events, if I don't block it it will
just exit. As mentioned I've tried putting a sleep loop in an it STILL
doesn't get teh events.
What I seem to need is some kind of 'yeild' or message loop functionality.
Is there such - not obvious to a quick look.
This seems an unlikley deficiency in dot net. What am I missing?
Iain
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:Op**************@TK2MSFTNGP11.phx.gbl... You can try the following. In the .NET application, launch a separate
thread that would only wait for an event. When the event is set, this thread
would notify the main thread by invoking some method through Form.Invoke() and immediately exit.
-- Dmitriy Lapshin [C# / .NET MVP] X-Unity Test Studio http://x-unity.miik.com.ua/teststudio.aspx Bring the power of unit testing to VS .NET IDE
Iain,
I'd suggest receiving *COM* events on the main thread that should never be
blocked. To make the worker thread wait, introduce an AutoResetEvent that
the worker thread would wait for. Thus, the worker thread will be sleeping
until the AutoResetEvent is signaled. And after the event is signaled, the
worker thread will do some useful work and go to sleep until the
AutoResetEvent is signaled for the next time.
The main thread, in turn, will be signaling the AutoResetEvent every time it
receives a COM event. If you need to pass some params to the worker thread
before it starts its work, introduce a thread-safe parameter object
accessible to both threads.
Or, and it might be even better! - you can employ the ThreadPool. Every time
the main thread receives a COM event, it queues a work item on the thread
pool, thus avoiding any "home-made" thread care.
--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE
"Iain" <id********@dircon.co.uk> wrote in message
news:eG**************@TK2MSFTNGP09.phx.gbl... Hmm. I'm trying to get my head round this (sorry, I've taken some time
out to do some higher level stuff, now back to the detail).
Basically, this will end up as a server process - possibly a service, so I can't rely on UI level stuff like timers of Form.Invoke.
I've taken the waitforone out as an experiment and also the stuff that's meant to follow afterwards (leaving the code to return to the test UI) and the events come through fine.
I've tried setting the process of on another thread, but that failed. Reasonably enough as I guess the thread that could receive the messages is still locked and therefore will not peek the equivalent of a message loop (which seems to be the essential problem) - I am by the way, reasonbly convinced that I could have done this in unmanaged C++ 6 without this
class of problem, though in truth I haven't tried it.
I can't actually see any way of setting of a thread which just waits for
the events. If I block it, it wont get the events, if I don't block it it
will just exit. As mentioned I've tried putting a sleep loop in an it STILL doesn't get teh events.
What I seem to need is some kind of 'yeild' or message loop functionality. Is there such - not obvious to a quick look.
This seems an unlikley deficiency in dot net. What am I missing?
Iain "Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote in message news:Op**************@TK2MSFTNGP11.phx.gbl... You can try the following. In the .NET application, launch a separate thread that would only wait for an event. When the event is set, this thread would notify the main thread by invoking some method through Form.Invoke() and immediately exit.
-- Dmitriy Lapshin [C# / .NET MVP] X-Unity Test Studio http://x-unity.miik.com.ua/teststudio.aspx Bring the power of unit testing to VS .NET IDE
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Iain |
last post by:
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...
|
by: Chris B. |
last post by:
If anyone can figure out how to implement the following C++ function in C#
using interop, I'd be very appreciative.
I have not been successful in getting it to work correctly using interop...
|
by: bb |
last post by:
I have a windows network device driver written in c++ and a user
interface im porting to c#, my problem is i dont seem to be getting
notified of the event calls from the driver to the c# app
im...
|
by: Charles Law |
last post by:
I have a frustrating problem where WaitOne does not return when I expect.
I am using an AutoResetEvent with an overlapped structure in a call to
WaitCommEvent. The data I am expecting on the...
|
by: juli jul |
last post by:
Hello,
How can I know that the Manual Reset Event object done WaitOne(). I have
a condition and I want to do Set() to Manual Reset Event in it but I
have to know that there WaitOne() was done on...
|
by: qiangdi_he |
last post by:
Hi, Pals,
I am using WaitAny( ) to wait for the events triggered by a timer. But
it seems like that when the timer's interval elapsed, and the event was
set, but WaitAny is still waiting there....
|
by: Ed Sutton |
last post by:
Can any one please offer any theories on how ManualResetEvent.WaitOne
can hang when used with a timeout?
When I notice my USB/Serial devices are no longer receiving
communications, I hit break...
|
by: Christopher Carnahan |
last post by:
I need to figure out how to terminate a thread while it is blocked trying to
create a COM object via interop.
In a worker thread, I do something like this:
Type t = null;
Object...
|
by: Kürşat |
last post by:
Hi all,
I have a named autoreset event (EventWaitHandle) and two applications one
waits on the event and one sets the evet. Application A calls Set method and
free a thread in application B....
|
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,...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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,...
|
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...
| |