PC Review


Reply
Thread Tools Rate Thread

Raise event from library worker thread.

 
 
Johan
Guest
Posts: n/a
 
      30th Jun 2003
Hi!

I am writing a library in managed C++ for the .NET framework. I have
problems fireing events from a worker thread. The managed event must
be raised from the main thread, but I cannot find any way to pass
control from the worker thread to the main thread.

In the COM programming model the problem was solved by creating an
invisible window which the worker thread passed win32 messages to.
With what is that paradigm replaced in .NET?

I have found some solutions that involves the Control.Invoke method.
This approach works if you got access to the clients Form handle, but
since I am writing a library (and not a control) I don't now how to
get that. Instead I get this error message if a I let my class inherit
from Control and then call Invoke()

"An unhandled exception of type 'System.InvalidOperationException'
occurred in system.windows.forms.dll

Additional information: Cannot call Invoke or InvokeAsync on a control
until the window handle has been created."

Do anyone have the solution of how to raise events from a .NET
library's worker thread? I would be more than pleased if I anyone gave
me some key information!

Regards,
John
 
Reply With Quote
 
 
 
 
Alex Feinman [MVP]
Guest
Posts: n/a
 
      30th Jun 2003
You can use MessageWindow class in a same way you used hidden window in COM

"Johan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi!
>
> I am writing a library in managed C++ for the .NET framework. I have
> problems fireing events from a worker thread. The managed event must
> be raised from the main thread, but I cannot find any way to pass
> control from the worker thread to the main thread.
>
> In the COM programming model the problem was solved by creating an
> invisible window which the worker thread passed win32 messages to.
> With what is that paradigm replaced in .NET?
>
> I have found some solutions that involves the Control.Invoke method.
> This approach works if you got access to the clients Form handle, but
> since I am writing a library (and not a control) I don't now how to
> get that. Instead I get this error message if a I let my class inherit
> from Control and then call Invoke()
>
> "An unhandled exception of type 'System.InvalidOperationException'
> occurred in system.windows.forms.dll
>
> Additional information: Cannot call Invoke or InvokeAsync on a control
> until the window handle has been created."
>
> Do anyone have the solution of how to raise events from a .NET
> library's worker thread? I would be more than pleased if I anyone gave
> me some key information!
>
> Regards,
> John


 
Reply With Quote
 
Johan
Guest
Posts: n/a
 
      7th Jul 2003
Thanks for your answer, but as I understand it MessageWindow is only
implemented in the Compact Framework and not the desktop framework. At
least the docs say so, and the postings from Microsoft staf in those
groups say so.

Any solution for .NET Desktop Framework?

Regards,
John

"Alex Feinman [MVP]" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> You can use MessageWindow class in a same way you used hidden window in COM
>
> "Johan" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi!
> >
> > I am writing a library in managed C++ for the .NET framework. I have
> > problems fireing events from a worker thread. The managed event must
> > be raised from the main thread, but I cannot find any way to pass
> > control from the worker thread to the main thread.
> >
> > In the COM programming model the problem was solved by creating an
> > invisible window which the worker thread passed win32 messages to.
> > With what is that paradigm replaced in .NET?
> >
> > I have found some solutions that involves the Control.Invoke method.
> > This approach works if you got access to the clients Form handle, but
> > since I am writing a library (and not a control) I don't now how to
> > get that. Instead I get this error message if a I let my class inherit
> > from Control and then call Invoke()
> >
> > "An unhandled exception of type 'System.InvalidOperationException'
> > occurred in system.windows.forms.dll
> >
> > Additional information: Cannot call Invoke or InvokeAsync on a control
> > until the window handle has been created."
> >
> > Do anyone have the solution of how to raise events from a .NET
> > library's worker thread? I would be more than pleased if I anyone gave
> > me some key information!
> >
> > Regards,
> > John

 
Reply With Quote
 
Maarten Struys
Guest
Posts: n/a
 
      8th Jul 2003
One of the reasons Chris is talking about is undoubtfully the fact that
smart device development can only be done using C# and VB.NET, not with
managed C++. You might assume that the generated IL is the same, but the
..NET CF only exposes a subset of the methods of the full framework, so
undoubtfully you would run into problems if getting the library running at
all (I have to admit I never tried this, not even with a trivial library,
mainly since I don't have the need for it).


--
Regards,

Maarten Struys
PTS Software bv
----
"Johan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Chris,
>
> Why not list the reasons why this issue is "not relevant" to the
> compact framework. For me it is indeed relevant because I'm trying to
> find the best solution for both the compact and the desktop framework.
>
> Maybe those "several reasons" contains some good information. Share
> your knowledge instead of being slightly... ;-)
>
> /John
>
> "Chris Tacke, eMVP" <(E-Mail Removed)> wrote in message

news:<(E-Mail Removed)>...
> > Quit posting to multiple groups. This is completely not relevant to the
> > Compact Framework for several reasons.
> >
> > --
> > Chris Tacke, eMVP
> > Advisory Board Member
> > www.OpenNETCF.org
> >
> >
> > "Johan" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > Hi!
> > >
> > > I am writing a library in managed C++ for the .NET framework. I have
> > > problems fireing events from a worker thread. The managed event must
> > > be raised from the main thread, but I cannot find any way to pass
> > > control from the worker thread to the main thread.
> > >
> > > In the COM programming model the problem was solved by creating an
> > > invisible window which the worker thread passed win32 messages to.
> > > With what is that paradigm replaced in .NET?
> > >
> > > I have found some solutions that involves the Control.Invoke method.
> > > This approach works if you got access to the clients Form handle, but
> > > since I am writing a library (and not a control) I don't now how to
> > > get that. Instead I get this error message if a I let my class inherit
> > > from Control and then call Invoke()
> > >
> > > "An unhandled exception of type 'System.InvalidOperationException'
> > > occurred in system.windows.forms.dll
> > >
> > > Additional information: Cannot call Invoke or InvokeAsync on a control
> > > until the window handle has been created."
> > >
> > > Do anyone have the solution of how to raise events from a .NET
> > > library's worker thread? I would be more than pleased if I anyone gave
> > > me some key information!
> > >
> > > Regards,
> > > John



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access Control In a Form From Library Function on Worker Thread joey.powell@topscene.com Microsoft C# .NET 2 5th Apr 2006 07:57 PM
Fire event from Worker thread and handle in UI thread =?Utf-8?B?SmVzIFJhbXNpbmc=?= Microsoft Dot NET Framework Forms 0 30th Jun 2005 03:17 PM
How to Raise an Event on a Different Thread Charles Law Microsoft VB .NET 4 9th Jun 2004 02:55 AM
Re: Raise event from library worker thread. Alex Feinman [MVP] Microsoft VC .NET 1 7th Jul 2003 11:53 PM
Raise event from library worker thread. Johan Microsoft Dot NET Framework 2 7th Jul 2003 11:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:43 PM.