Re: Help me with threads.
From: Bruno Jouhier [MVP] (bjouhier_at_club-internet.fr)
Date: 01/21/05
- Next message: Willy Denoyette [MVP]: "Re: Starting a windows app from a service"
- Previous message: Nadav: "Custom formatter creation"
- In reply to: Jon Skeet [C# MVP]: "Re: Help me with threads."
- Next in thread: Jeff Louie: "Re: Help me with threads."
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 21 Jan 2005 22:14:44 +0100
"Jon Skeet [C# MVP]" <skeet@pobox.com> a écrit dans le message de news:
MPG.1c5b4d62f0ae3f8398bc59@msnews.microsoft.com...
> Bruno Jouhier [MVP] <bjouhier@club-internet.fr> wrote:
>> > Just to correct something - Swing and AWT (and possibly SWT as well,
>> > not sure) also require you to only access UI objects in the UI thread.
>> > That's what SwingUtilities.invokeLater/invokeAndWait are for.
>>
>> Then, they have changed things since I used these toolkits. I worked with
>> the first releases (AWT in 96-98, just a little bit of Swing, no SWT but
>> I
>> assumed it was the same) and there was no such thing at the time (but
>> lots
>> of ugly deadlocks in AWT). They probably had to go this way to be able to
>> take advantage of the fast MFC controls when running on Windows, and to
>> get
>> rid of their awful deadlocks.
>
> Swing has always been the same, as far as I'm aware. I'm not sure about
> AWT, but I doubt that they'd make such a breaking change late on. It
> may well not have been well documented, of course...
I looked a bit more into this:
Swing and SWT are not free-threaded (except for some very specific calls in
the Swing toolkit). So, you have to go through the invoke calls if you are
calling from another thread. And I was completely wrong on those (I
extrapolated too quickly from my early AWT experience).
AWT sounds more complex: internally, there is a single thread that accesses
the message queue and the drawing methods, but externally, you are allowed
to call the AWT methods from several threads. This leads to extra complexity
and inefficiencies in the toolkit, which is why a different approach was
taken by Swing and SWT. So, from what I've found on Google (which is not
always very clear), it seems that AWT is still free threaded from the
outside, even if it is single threaded inside.
Actually, it would not be too difficult to turn the WinForms toolkit into a
free threaded toolkit "from the outside", you would just need to rewrite
every public API entry point as:
foo()
{
if (InvokeRequired)
BeginInvoke(new FooDelegate(internalFoo));
else
internalFoo();
}
The toolkit would then be free threaded "from the outside" but it would be
slower.
Bruno.
>
> --
> Jon Skeet - <skeet@pobox.com>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too
- Next message: Willy Denoyette [MVP]: "Re: Starting a windows app from a service"
- Previous message: Nadav: "Custom formatter creation"
- In reply to: Jon Skeet [C# MVP]: "Re: Help me with threads."
- Next in thread: Jeff Louie: "Re: Help me with threads."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|