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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:11:20+00:00 2026-05-31T17:11:20+00:00

I have a project where I need to update a labels text from inside

  • 0

I have a project where I need to update a labels text from inside another classes method. It’s worth noting that this method is being called from a Background worker thread.

I have tried passing in the text to update as a UserState Obj in the Workers ReportProgress(); method and then updating the label when the workers progress changed event is fired off on the main form. This works, but obviously only updates the labels text when the progress changed event is raised.

I have code that’s loading/removing proxies constantly and I need a label to show this as it happens (as opposed to only updating when the bg workers progress changed event fires). Hopefully someone can help.

Thanks

Edit* Here’s some code to make the problem a little easier to understand: –

  public string Request(string action)
    {

        if (string.IsNullOrWhiteSpace(action))
        {
            return "";
        }

        HttpWebRequest req;

        string response = string.Empty;
        while (response.Equals(string.Empty) && proxy != null)
        {
            try
            {
                req = (HttpWebRequest)WebRequest.Create(action);
                req.Proxy = proxy;
                response = new StreamReader(req.GetResponse().GetResponseStream()).ReadToEnd();
            }
            catch (Exception ex)
            {
                RemoveProxy(proxy);
                MessageBox.Show("Proxy Removed: " + proxy.Address.ToString());

                proxy = GenNewProx();
                MessageBox.Show("New proxy" + proxy.Address.ToString());
            }
        }

        return response;
    }

^^^ – Where i need to set the labels text, using Msgboxs at the moment but updating a label on the main form is obviously preferable

   foreach (string url in URLs)
        {
            result.URL = url;
            result.Shares = grabber.GetFacebookShares(url);
            result.Tweets = grabber.GetTweetCount(url);
            result.PlusOnes = grabber.GetPlusOnes(url);

            bgWorker.ReportProgress((outputGridView.Rows.Count * 100) / importGridView.Rows.Count, result);
        }

^^^ – Inside the bg workers do_work method on the main form.

2nd Edit*

I’m a bit new to events but could i not fire off a custom event say Proxy_Changed everytime i switch proxys and pass in a string argument with the new proxy/msg w.e and then subscribe to this event in the main form, then set the label on the main forms text = the string args when this event fires off? I’m probably talking jibberish tbh though :/

  • 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-31T17:11:21+00:00Added an answer on May 31, 2026 at 5:11 pm

    It sounds from your question and subsequent comments to other answers that you are running your code within a WinForms project, correct me if I am wrong? In a winform the main program thread is usually always static (static void Main()) therefore you must make your EventHandler static also to avoid null exceptions. I believe this will resolve your issue as it sounds like the rest of your code is correct?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an older project that I need to do an update for. However,
I have this non standard situation where i need to update object inside readOnly
The Junits I have in my project need to load property files from the
I have a project that I'm working on and I need to be able
I have an old product that I need to update, written in C# and
For my project i need to have custom urls that should not be easy
I have a vb6 project and i need to update a visual foxpro table
I have a project that is stored in a Subversion repository. In this repository,
I have a pylons project where I need to update some in-memory structures periodically.
So I have a project that uses the old-style encodeObject:/decodeObject NSCoder serialization. I need

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.