Re: Executing a method in a given thread context
- From: "Francois PIETTE" <fpiette@xxxxxxxxxxxxxxxxx>
- Date: Tue, 8 Aug 2006 14:52:05 +0200
??>> The only built-in way to force execution on a specific thread, isvia
??>> the 'Invoke' method of a control.
FP> This is valid only for the UI thread, not any arbitrary thread.
UI thread is an common thread with with message loop.
Yes, I know, but this is not the issue.
To respecify the problem:
1) I'm building a non-visual component (porting win32 to .NET)
2) This component use an asynchronous socket (GeginReceive and the likes)
3) Asynchronous callbacks are called in the context of a worker thread
created by the runtime
4) The component user doesn't have to worry about multithreading (This is
the main goal, what I want)
5) The component user can create my non-visual component in any thread (The
UI thread is just a common thread for simple applications. More serious
applications could create the component within an arbitrary worker thread)
6) The component trigger events such as "SessionConnected" or
"DataAvailable".
7) The issue: because of (3), then (6) mean the event handler is executed in
the worker thread context. I want to use an intermediate layer which force
the event handler to execute in the context of the thread which created the
component at the first place.
8) Under Win32, I implement (7) very easily using a hidden window and a few
custom messages. Of course the component user need a message loop in his
thread to have the component working properly. The message loop is created
in the main thread automatically in any GUI application. In other
applications or in secondary thread, the component user has to create a
message loop.
9) To help the component user, the win32 component I created has a message
loop
When using a component designed as I describe, a developer can build an
application using the asynchronous model without ever worrying about
multithreading issues. All is application code is executed in the context of
is thread (most frequently the UI thread). All the multithreading issues are
moved out of the developer mind, they are built into the component.
I can do everything I said above. I've done it and it works. But I'm new to
..NET and C# and I don't like calling win32 API directly. Microsoft do it in
Microsoft.Win32.UnsafeNativeMethods which is called from many many places
elsewhere. I can't call Microsoft.Win32.UnsafeNativeMethods myself because
they are private. I want to write my code as clean and lean as possible.
That's why I ask.
--
Francois PIETTE
http://www.overbyte.be
.
- References:
- Executing a method in a given thread context
- From: Francois PIETTE
- Re: Executing a method in a given thread context
- From: AJ
- Re: Executing a method in a given thread context
- From: Francois PIETTE
- Executing a method in a given thread context
- Prev by Date: Re: Executing a method in a given thread context
- Next by Date: Re: Executing a method in a given thread context
- Previous by thread: Re: Executing a method in a given thread context
- Next by thread: Re: Executing a method in a given thread context
- Index(es):
Loading