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 3303390
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:57:07+00:00 2026-05-17T20:57:07+00:00

Hello Why I haven’t access to my private control on form (e.g. ListBox) from

  • 0

Hello
Why I haven’t access to my private control on form (e.g. ListBox) from a static method?
How to update control in this case?

EDIT 1.

my code:

ThreadStart thrSt = new ThreadStart(GetConnected);
        Thread thr = new Thread(thrSt);
        thr.Start();

and

static void GetConnected()
    {
        //update my ListBox
    }

So it must be void, without param and be static, right?

EDIT 2.

If someone need solution in WPF then should try this:

private void GetConnected()
    {
        myListBox.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
                    new Action(() =>
                    {
                        myListBox.Items.Add("something");
                    }
                               )
                 );
    }
  • 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-17T20:57:08+00:00Added an answer on May 17, 2026 at 8:57 pm

    Static methods cannot access instance state (such as a non-static control). Either remove static from the method declaration, or pass a reference to the control as argument to the method:

    private static void SomeMethod(ListBox listBox)
    {
        listBox.Items.Add("Some element");
    }
    

    …and call it like so:

    SomeMethod(MyListBox);
    

    Update
    There are different ways to do asynchronous things in the UI (now assuming winforms). I would recommend you to look into using BackgroundWorker (search here on SO; plenty of examples). If you really want to do it by creating threads on your own, here is one way to do that:

    private void SomeMethod()
    {
        string newElement = FetchNextElementToAdd():
        SafeUpdate(() => yourListBox.Items.Add(newElement));
    }
    
    private void SafeUpdate(Action action)
    {
        if (this.InvokeRequired)
        {
            this.BeginInvoke(action);
        }
        else
        {
            action();
        }
    }
    

    …and to call it:

    Thread thread = new Thread(SomeMethod);
    thread.Start();
    

    You can also use the thread pool (preferred over creating your own threads, given that you don’t expect them to run for very long):

    ThreadPool.QueueUserWorkItem(state => SomeMethod());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello i have this form filling javascript: function onLine(code,nn) { document.writeform.bericht.value+=code; document.writeform.bericht.focus(); document.writeform.nickname.value+=nn; write1();
Question: Considering the hello-gl2 example from Android NDK r6b, is this example correct when
This example works fine: static char *daytab[] = { hello, world }; This doesn't:
Hello I have the following code namespace ConsoleApplication2 { class Program { static void
Hello I have been having trouble with this for a while now. I have
Hello I have this list that i am working on. When i move the
Hello I am new to android programming, I haven't started writing the code for
Hello I've started to learning AS3 from one book and found something I don't
I created a Hello world app but get this strange error: The project cannot
I tried googling this and I haven't found an answer yet to my problem.

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.