Windows Form Threading

suchiate

Member
Joined
Jan 4, 2006
Messages
11
Programming Experience
1-3
hey,

i am writing an application that runs multiple window forms as objects and i would like to run them in different threads.. may i know how i can do that?
right now i am using the following code:

GrabThread(0) = New Thread(AddressOf New frm1().Show)
GrabThread(0).Start()

the windows displays for 0.5 second and disappears.. may i know how to keep the window running in the thread? please help me out.. thanks
 
You need to post the entire code. Looks like you are trying to show the same form with many threads. That isn't making since to me. Please send the alottment of code associated with this process. Thanks :)

Not to mention Forms exist within their own threads anyways. I mean you have the process but forms are already opened on seperate threads. Just form1.show() form2.show() ect will do that. Please explain also what you want to accomplish. :)
 
i have a function which will use web request and response objects to read HTML information from webpages.. but while they are parsing the html codes.. the application hangs until the response returns.. therefore i need to put it in a separate thread.. and i want to continuously grabbing the html information every 2 minutes.. so i have a timer as well.. below is the following code followed by the problem i am facing...


GrabThread as new thread(addressof sub1)

sub1 is the procedure which will grab information from the internet.. and after grabbing the information..

tmrUpdate.enabled = true
GrabThread.Abort()

however.. it is suppose to make the timer running as it worked before i apply threading to sub1... so i don know how i can solve this..
 
Ok, the code you posted at the top and the code you have now and are asking for is confusing to me. But what I am gathering is that you basically want to make an update to the form via a seperate thread b/c it hangs up the application too long. You have a good idea already how to do that but again w/o code I can't tell you what you are doing wrong.

Continue what you have started b/c it seems to be the correct logic.

Make an entire routine for the form update within a sub routine or routines. - Have the timer make a new thread and start it on that routine every two minutes.

There's nothing wrong with that logic as far as I can see unless you have multiple threads accessing the same objects ect.... But as far as just getting it to work again I need to see the code. I don't know what you've done wrong.
 
hey, i have tried using timer already... below is my code

VB.NET:
PrivateSub tmrGrab_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrGrab.Tick
If (blnFirstTime = True) Then
blnFirstTime = False
GrabThread = New Thread(AddressOf GrabLive)
GrabThread.IsBackground = True
GrabThread.Start()
Else
If (intCount = 0) Then
lblCountdown.Text = "00:02:00"
datNextUpdate = Date.Now.AddSeconds(120)
intCount = 1
ElseIf (intCount < 121) Then
intCount += 1
timeNextUpdate = datNextUpdate.Subtract(Date.Now)
If (timeNextUpdate.Seconds < 0) Then
lblCountdown.Text = "00:00:00"
Else
lblCountdown.Text = String.Format("{0:d2}:{1:d2}:{2:d2}", timeNextUpdate.Hours, timeNextUpdate.Minutes, timeNextUpdate.Seconds)
EndIf
ElseIf (intCount = 121) Then
intCount = 0
GrabThread = New Thread(AddressOf GrabLive)
GrabThread.IsBackground = True
GrabThread.Start()
EndIf
EndIf
EndSub
after the first time i call the grabbing sub which is GrabLive.. after 2 minutes.. which is when the counter reaches 120. it will call a new thread for the GrabLive to update again.. but the problem here is.. the timer stops after the first time the thread is called.. can anyone help me?
 
Last edited by a moderator:
Back
Top