My Application Hangs when I use the stylus on the screen while a thread is running

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

My application loops through each unit in an array and displays it on the
screen (in a label) for a pre-set amount of time.

It runs fine, but while it's running if I move my stylus around the screen
or "mouseover" buttons on my form or click on the menu, the system will
freeze up. I've tried taking out blocks of code in the thread to find the
trouble spot but it hangs ragardless. I've tried Try-Catch-Finally-End Try
statements and they don't catch an error (the application just freezes.
I've tried On Error Resume Next with the same result. Below is my code for
the thread if that helps:

Private Sub DisplayText()

Dim ReadingWord As String

CurrentTextArrayItem = 0

Dim SentenceItem As String

Dim Counter As Integer

If Not WordNumberSearchingFor > 0 Then

WordNumberSearchingFor = 0

End If

CurrentTextArrayItem = WordNumberSearchingFor



FirstSentenceHit = True

For Counter = WordNumberSearchingFor To EntireTextArray.Count

Try

LocalTextSpeed = scroll_Speed.Maximum + scroll_Speed.Minimum -
scroll_Speed.Value()

If Microsoft.VisualBasic.Len(lbl_Word.Text) > 0 Then

System.Threading.Thread.Sleep(LocalTextSpeed)

lbl_Word.Text = EntireTextArray.Item(Counter)



End If

Catch ex As Exception

MsgBox("caught error and exiting - " & ex.Message.ToString)

Application.Exit()

Finally

CurrentTextArrayItem = 1 + CurrentTextArrayItem

End Try

Next



End Sub
 
You're updating the UI from a worker thread which is illegal and causes lock
ups. Use Control.Invoke to marshal calls back to the thread that created
the UI.

-Chris
 
Thanks for the response. I understand that I need to use control.invoke
somehow instead of just updaing the ui from the thread. Where do I use
control.invoke? Also, when I try to type
system.windows.forms.control.invoke - I cannot access the invoke method. Is
it not available in the .NET compact framework? Thanks,

-Dave
 
Everybody here is great. Thanks for all the great links. I'm on it right
now and can't wait to resolve my problem.
 
Back
Top