Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Re: Access or SQL

 

Split from http://www.xtremedotnettalk.com/showthread.php?t=101879

 

I want to catch events in my main form and change the title to match the input from the event. I'm getting errors about crossthreading. Can some one please help me get this small test program working?

 

Here is the whole code:

Code:

 

Public Class Form1

 

Private WithEvents Worker As New WorkerClass

 

Private Sub Worker_ProgressChanged(ByVal Progress As Integer) Handles Worker.ProgressChanged

Me.Text = Progress

End Sub

 

End Class

 

Code:

 

Public Class WorkerClass

 

Public Event ProgressChanged(ByVal Progress As Integer)

Private t As Threading.Thread

 

Public Sub New()

t = New Threading.Thread(AddressOf MainThread)

t.Name = "BackgroundThread"

t.IsBackground = True

t.Start()

End Sub

 

Private Sub MainThread()

Dim Progress As Integer = 0

Do Until Progress = 10

Threading.Thread.Sleep(1000)

Progress += 1

RaiseEvent ProgressChanged(Progress)

Loop

End Sub

 

End Class

 

 

___________________________

Watch The Ides of March Online for Free

Edited by PlausiblyDamp
  • Administrators
Posted

Re: Access or SQL

 

You can't update a UI element from a non UI thread, your ProgressChanged event is being raised on the background thread and as such is causing this problem.

 

Is there a reason you aren't using the built in BackgroundWorker component as you seem to be emulating it's way of doing things.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...