473,503 Members | 6,354 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Attaching a thread

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.Apa rtmentState.STA)

MyBackgroundThread.IsBackground = True

MyBackgroundThread.Start()

Thanks,

Adam
May 10 '06 #1
3 1154
"Adam Honek" <Ad*******@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/>

May 10 '06 #2
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]" <hi***************@gmx.at> wrote in message
news:up**************@TK2MSFTNGP05.phx.gbl...
"Adam Honek" <Ad*******@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/>

May 11 '06 #3
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.
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> escribió en el mensaje news:OY**************@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]" <hi***************@gmx.at> wrote in message
| news:up**************@TK2MSFTNGP05.phx.gbl...
| > "Adam Honek" <Ad*******@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/>

May 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
9926
by: Yvan J. Gagnon | last post by:
I am currenly developing a web site using Macromedia fireworks, and am trying to figure out a way (through hand-coding) of attaching a javascript function (onClick="doit=false") to each of the...
0
1327
by: Trokey | last post by:
I am having a serious problem connecting to out-of-process COM objects in my windows service application. Whenever I try to create an instance of the COM object, a second instance of the COM server...
5
1689
by: nukiboy | last post by:
========= test.js =================== function Test() { this.temp = "hehehehe" ; this.method1 = method1 ;
5
2345
by: knocte | last post by:
Hello. I am a web developer very worried about "bloat code" and "languages mixture". So, since some time, I always try to avoid completely the use of javascript in XHTML/HTML files. This leads...
1
4703
by: Mark Kamoski | last post by:
Hi-- All of sudden (?) the VS.NET v1 IDE is NOT automatically attaching aspnet_wp.exe as a debugged process. Why? Here is the situation. VS.NET (v1)
2
1513
by: Mike W | last post by:
I am using thread.GetNamedDataSlot and thread.SetData to attach data to a thread inside of a class library which in turn is used by an asp.net 2.0 application. For the most part it works but we...
6
19223
by: Daz | last post by:
Hello everyone, I would like to open a child window from the parent, and add an onload event listener to the child window which will tell the parent when the document has loaded. As far as I...
2
2073
by: Steve Potter | last post by:
I am trying to find some method of attaching a Listbox object to a list object so as the contents of the list are changed the contents of the Listbox will be updated to match. I have found a few...
1
1761
by: moltendorf | last post by:
I have a simple XMLHttpRequest that grabs a list of messages from my server (I posted a question for a different aspect of this earlier) I have decided to improve on it a little by adding in...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7291
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5598
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1522
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
402
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.