Solved

brackground worker help with a listview visual basic

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

Suggested Solutions

Title # Comments Views Activity
Run a batch file when a Crystal Report is opened 5 49
.NET 2008 VB and C# 6 39
Convert Ctime to date time in textfile? 7 32
How to repeat the data 4 18
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

837 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