Willy
Mon May 09 07:12:44 CDT 2005
"Ioannis Vranos" <ivr@remove.this.grad.com> wrote in message
news:OpWTf6IVFHA.2664@TK2MSFTNGP15.phx.gbl...
> Jon Skeet [C# MVP] wrote:
>
>> It's got nothing to do with the STA requirement of Forms - it's a
>> fundamental Windows GUI programming requirement that you only access a UI
>> component on the thread which created it.
>>
>> Howveer, it shouldn't be particularly complicated to update the UI
>> appropriately.
>>
>> See
http://www.pobox.com/~skeet/csharp/threads/winforms.shtml
>
>
> I am currently reading .NET networking (and have read .NET multithreading
> in the past), and I see no problem updating GUI components from different
> threads. In addition, STA etc have nothing to do with pure .NET
> applications (applications that do not use COM and other past APIs).
>
> For example we can update a TextBox from different threads upon receiving
> or sending data (in the chat client example). In fact this is what I am
> currently reading about, Chat client/server applications using connection
> (TCP/IP stream sockets) and connectionless (UDP) String exchanges.
>
>
> Am I missing something?
>
Yes, a fundamental rule in Windows that say's that Windows handles (HWND's)
have thread affinity, that means they should not be used from another thread
than the owning thread. Note that v2.0 contains a debug user probe that
warns you about cross-thread access to window UI elements.
Also note that the UI thread needs to run in a STA because some of the UI
controls might use COM under the covers. Another reason to have the thread
running in a STA is that and Cut/Paste (Clipboard access) is using OLE based
and needs a STA to run.
Willy.