Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6124185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:06:14+00:00 2026-05-23T16:06:14+00:00

I am writing a WinForms application in C# .NET and want to update the

  • 0

I am writing a WinForms application in C# .NET and want to update the listview from the worker thread. I have read just about every post here on this but don’t really fully understand the use of Invoke and delegates. In fact a few examples on here won’t even compile as it complains of calling a non-static control from a static function.

I have a ListViewItem which I just want to pass to the UI thread via AddListItem(…). What is the best way to do this?

At present I have

this.lvcontrol.Invoke(new Action(() => lvcontrol.Items.Add(item)));

This is from MyForm::AddListView() which is a static function. But of course the compiler complains that you can’t call “this” or just “lvcontrol” from a static method. If the method isn’t static I can’t call the method from the static worker thread which is a member function of the Form.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:06:14+00:00Added an answer on May 23, 2026 at 4:06 pm

    You need a reference to the lvcontrol in order for the code to know which one you are trying to update (you could have two copies of the form open!).

    If lvcontrol is a variable then drop the this at the begining eg

    lvcontrol.Invoke(new Action(() => lvcontrol.Items.Add(item))
    

    If it isn’t your code is going to either all have to be non-static or you will need to pass a reference to the form around (and use that reference instead of the this, eg if frm is a reference to the form

    frm.lvcontrol.Invoke(new Action(() => frm.lvcontrol.Items.Add(item))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a WinForms application and want to have an MVC-Type Design. Actually it's
I'm writing a .NET 3.5 application (WinForms) which uses classes from an external DLL
I'm writing a winforms application in C# (.NET 4.0, using EntityFramework). I wanted to
I am writing a .NET WinForms application that needs to display a list of
I'm writing a VB.Net WinForms application that has multiple data girds on any given
I'm writing a test WinForms / C# / .NET 3.5 application for the system
Our application needs to communicate via a H2 database (JDBC) from .Net Framework (WinForms).
I'm writing a small business Winforms application in C#, .NET 4.0, using Entity Framework
I have a basic VB.Net application that gets data from some websites and then
I'm planning on writing a medium-size WinForms application that I'll write in C#, .NET

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.