Solved

brackground worker help with a listview visual basic

Posted on 2014-03-24
3
252 Views
Last Modified: 2014-03-24
My application will update a label depending on if it can ping a workstaion in the background.  This part works fine, but I would also like the background worker to ping a list of workstations for a listview and update the listview in the background.  When I added the code to check the listview I'm getting a cross threaded opperation error.  How can I get this to work?

 'background for ping check
    Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        Try

            e.Result = My.Computer.Network.Ping(strWorkstation, 1000)
        Catch ex As Exception

        End Try


        'change forecolor to red for workstations that have a user logged in them
        For i As Integer = 0 To ListView1.Items.Count - 1

            If PingCheck(ListView1.Items(i).SubItems(0).ToString) = True Then

                ListView1.Items(i).ForeColor = Color.Green
            Else
                ListView1.Items(i).ForeColor = Color.Red
            End If

        Next
    End Sub
0
Comment
Question by:chadmanvb
  • 2
3 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 39950342
Hi chadmanvb;

That is because you are trying to update the UI from a thread that did not create the UI itself. Please see the following MSDN article on how it can be done.

Updating the UI from a Secondary Thread
0
 

Author Closing Comment

by:chadmanvb
ID: 39950748
Thanks!
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 39950805
Not a problem, glad to help.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now