Home All Groups Group Topic Archive Search About
Author
10 May 2006 8:22 AM
Adam Honek
How does one attach a thread so it can update the UI of a form?

The other thing is I thought .IsBackground makes the thread active so it
doesn't stop looping until the main thread dies. This doesn't seem to be the
case however with it just dying after one run.

I recall there being a Win32 API by the name AttachThreadInput, is this the
answer?

I'm using the code below to launch the thread.

Dim MyBackgroundThread As System.Threading.Thread

MyBackgroundThread = New System.Threading.Thread(AddressOf
mybackgroundcheck)

MyBackgroundThread.SetApartmentState(Threading.ApartmentState.STA)

MyBackgroundThread.IsBackground = True

MyBackgroundThread.Start()

Thanks,

Adam

Author
10 May 2006 10:07 AM
Herfried K. Wagner [MVP]
"Adam Honek" <AdamHo***@Webmaster2001.freeserve.co.uk> schrieb:
> How does one attach a thread so it can update the UI of a form?

'Control.{InvokeRequired, BeginInvoke, Invoke}':

Multithreading in Windows Forms applications
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=multithreading&lang=en>

> The other thing is I thought .IsBackground makes the thread active so it
> doesn't stop looping until the main thread dies. This doesn't seem to be
> the case however with it just dying after one run.

'IsBackground' will cause the thread to be killed when the main thread it is
belonging to terminates.  You'll add additional logic such as a loop or
'Thread.Sleep' to your thread in order to prevent it from terminating.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
11 May 2006 1:15 AM
Adam Honek
1) MS has changed .resume and .suspend in .NET 2.0 but I can't
find how it's done now.

2) I can't see any info there regarding how to update a form in a different
thread. It seems a global variable must be used.

Still need to check if possibly any .begininvoke might do it.

Adam


Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:upUNEmBdGHA.4312@TK2MSFTNGP05.phx.gbl...
> "Adam Honek" <AdamHo***@Webmaster2001.freeserve.co.uk> schrieb:
>> How does one attach a thread so it can update the UI of a form?
>
> 'Control.{InvokeRequired, BeginInvoke, Invoke}':
>
> Multithreading in Windows Forms applications
> <URL:http://dotnet.mvps.org/dotnet/faqs/?id=multithreading&lang=en>
>
>> The other thing is I thought .IsBackground makes the thread active so it
>> doesn't stop looping until the main thread dies. This doesn't seem to be
>> the case however with it just dying after one run.
>
> 'IsBackground' will cause the thread to be killed when the main thread it
> is belonging to terminates.  You'll add additional logic such as a loop or
> 'Thread.Sleep' to your thread in order to prevent it from terminating.
>
> --
> M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
> V B   <URL:http://classicvb.org/petition/>
Author
11 May 2006 11:10 AM
José_Manuel_Agüero
Hello Adam,
1) Resume and Suspend methods are still there, although you shouldn't use them: it's recommended the use of AutoResetEvent or other synchronization mechanisms, so that your thread decides when it can become suspended.
2)Herfried has provided you with a link for that purpose. You use Invoke or BeginInvoke methods if you want to interact with the user interface. Anyway don't hesitate to use a global variable if you need it.

Regards.


Show quoteHide quote
"Adam Honek" <AdamHo***@Webmaster2001.freeserve.co.uk> escribió en el mensaje news:OYlflhJdGHA.4276@TK2MSFTNGP03.phx.gbl...
| 1) MS has changed .resume and .suspend in .NET 2.0 but I can't
| find how it's done now.
|
| 2) I can't see any info there regarding how to update a form in a different
| thread. It seems a global variable must be used.
|
| Still need to check if possibly any .begininvoke might do it.
|
| Adam
|
|
| "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
| news:upUNEmBdGHA.4312@TK2MSFTNGP05.phx.gbl...
| > "Adam Honek" <AdamHo***@Webmaster2001.freeserve.co.uk> schrieb:
| >> How does one attach a thread so it can update the UI of a form?
| >
| > 'Control.{InvokeRequired, BeginInvoke, Invoke}':
| >
| > Multithreading in Windows Forms applications
| > <URL:http://dotnet.mvps.org/dotnet/faqs/?id=multithreading&lang=en>
| >
| >> The other thing is I thought .IsBackground makes the thread active so it
| >> doesn't stop looping until the main thread dies. This doesn't seem to be
| >> the case however with it just dying after one run.
| >
| > 'IsBackground' will cause the thread to be killed when the main thread it
| > is belonging to terminates.  You'll add additional logic such as a loop or
| > 'Thread.Sleep' to your thread in order to prevent it from terminating.
| >
| > --
| > M S   Herfried K. Wagner
| > M V P  <URL:http://dotnet.mvps.org/>
| > V B   <URL:http://classicvb.org/petition/>