Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Thread Cross-thread operation not valid

Hav0c #1Hav0c #1 Posts: 50Member
Hey all
what i like to do is show a animated pictureBox while another function is being executed. Now the only way i know to do this is by using a thread.

this is a sample of my code.

[code] Private Sub ThreadTask()
'the pictureBox proparty is set to false that is why i am setting it to true now
picLoad.Visible = True
End Sub

Private Sub cmdFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFind.Click
If txtSearchText.Text = "" Then
MsgBox("Search fields can be empty.", MsgBoxStyle.Critical, "Input Error")
txtSearchText.Focus()
Else
trd = New Thread(AddressOf ThreadTask)
trd.Start()

'This is the other function that is being executed and it is in another class
DisplayResult(dgvSearch, 5, txtSearchText.Text)
trd.Abort()

End If[/code]

with the above code i get the following error "Cross-thread operation not valid" now i have read this article http://www.vcskicks.com/cross-thread.php and that is based on C# can any one help me translate it to VB.NET
Regards
Sign In or Register to comment.