Steve,
> Whats the best way to access .net GUI classes from a spawned thread? Is
> this even advisable, or is it a sign that the design is wrong?
It is certainly possible, and certainly necessary at times. It's not
necessarily a wrong thing, though in some cases there might be alternatives.
That said, you do have to take a few things into account, and make sure you
marshal the GUI access back to the main thread (so that you never touch the
gui controls from secondary threads), but, fortunately, the .NET framework
provides a mechanism for this.
Here's a good article on the topic (it's in C#, but the principles are the
same):
http://www.code-magazine.com/article.aspx?quickid=0403071&page=1

Signature
Tomas Restrepo
tomasr@mvps.org
http://www.winterdom.com/
Steve N. - 25 Jul 2005 17:11 GMT
> That said, you do have to take a few things into account, and make sure you
> marshal the GUI access back to the main thread (so that you never touch the
[quoted text clipped - 4 lines]
> same):
> http://www.code-magazine.com/article.aspx?quickid=0403071&page=1
Yes, I got it working, thank you.
> Whats the best way to access .net GUI classes from a spawned thread?
> Is this even advisable, or is it a sign that the design is wrong?
The design is not wrong, but you jmust be careful to make your GUI API
thread-safe : each public function of your GUI objects that may be called on
different threads should begin by something like this (in C# for ease of
syntax, but you've got the idea) :
delegate void DoSomethingDelegate(params...) ///DoSomethingDelegate matches
DoSomething'signature
void DoSomething(params....)
{
if (InvokeRequired)
{
BeginInvoke (new DoSomethingDelegate(DoSomething, new object[]
{params...}));
return;
}
//normal GUI stuff
}
Arnaud
MVP - VC