Solved

brackground worker help with a listview visual basic

Posted on 2014-03-24
3
253 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

861 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

24 Experts available now in Live!

Get 1:1 Help Now