Page 1 of 2

Threading?

Posted: Mon Mar 11, 2013 4:53 pm
by Dummy1912
Hello,

Seems my thread is only run 2x and then stops :(
anyone whats wrong?

'Form load
Code: Select all
        NewThread = New Thread(AddressOf Check0)
        NewThread.Start()


'Sub Check0
Code: Select all
        Me.Invoke(New Action(
          Sub()

              If status__.Text = 0 Then
                  GetStats()                  
              Else
                  GetStats()
              End If
          End Sub))
        Threading.Thread.Sleep(200)

it must run all the time and not just 2x
i even changed the sleep to 1000 but didn't do any different

anyone please?

Re: Threading?

Posted: Mon Mar 11, 2013 8:26 pm
by mandai
You would need to add a loop to keep the thread running.
This can be added in the Check0 sub:
Code: Select all
    Sub Check0()

        While True

            Me.Invoke(New Action(
              Sub()

                  If status__.Text = 0 Then
                      GetStats()
                  Else
                      GetStats()
                  End If
              End Sub))
            Threading.Thread.Sleep(200)

        End While

    End Sub

Re: Threading?

Posted: Mon Mar 11, 2013 10:47 pm
by Dummy1912
hello #mandai

thanks for reply me.
but seems now with the piece while true
my form keeps turning on and off :(

now i can't do anything because its go crazy
any idea?

thanks

Re: Threading?

Posted: Mon Mar 11, 2013 10:50 pm
by benji_19994
Watch this http://www.youtube.com/watch?feature=pl ... K5D4Y2fnl4

This should explain and help you with threading =D

Re: Threading?

Posted: Mon Mar 11, 2013 11:14 pm
by Dummy1912
yea thanks #benji_19994
everything they said i have showed here already :p
so this don't helped me much :)
thanks anyway ;)

Re: Threading?

Posted: Tue Mar 12, 2013 1:21 am
by Dummy1912
hello,

seems i got it working but how to fix it when you scroll up or down in a panel
i even set the thread to 1000
it freeze a sec :(
any idea how to make go smooth?
thanks

Re: Threading?

Posted: Tue Mar 12, 2013 5:31 am
by noypikami
its very well explained here.. this Link could be a help to you..
http://www.vbforums.com/showthread.php? ... -in-VB.Net

Re: Threading?

Posted: Tue Mar 12, 2013 8:43 am
by Dummy1912
hello #noypikami,

thanks :)
but i solved the thread like i said earlier :)
but still got a problem with scrolling :)
any idea?

Re: Threading?

Posted: Tue Mar 12, 2013 9:48 am
by Dummy1912
grrrrrrrr
drives me nuts
now the thread runs but if you wait a while before adding a new message
the thread has stops!!!!
how is this even possible when you use a while me.visible?????

seems we got this error in the thread ?
Image

any ideas?

Re: Threading?

Posted: Tue Mar 12, 2013 10:03 am
by noypikami
may be the problem is with the (while) or loop, coz the app cannot process
the thread when its still busy or in use.

try something like this............

Private Sub check0 (ByVal x As Boolean)
If x=true Then
' do something here
Else
'... do something here
End If
End Sub