Solved

brackground worker help with a listview visual basic

Posted on 2014-03-24
3
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 63

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 63

Expert Comment

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

688 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