Solved

brackground worker help with a listview visual basic

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net - TypeInitializer Error 25 25
VB.NET - Error - Object not set in Module 4 33
start a process from a service 3 21
location of a form 2 10
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…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 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

14 Experts available now in Live!

Get 1:1 Help Now