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

  • Home
  • SEARCH
  • 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 8851333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:07:48+00:00 2026-06-14T13:07:48+00:00

So I have this simple class that updates my labels, and it gets accessed

  • 0

So I have this simple class that updates my labels, and it gets accessed by different threads and reports progress of my application. It works fine however when closing this app this code always throws an error about trying to access something that is disposed.

private delegate void SetLabelTextDelegate(string str1, string str2);
public void SetLabelText(string str1, string str2)
{
    if (this.label1.InvokeRequired || this.label2.InvokeRequired)
    {
        this.Invoke(new SetLabelTextDelegate(SetLabelText), new object[] { str1, str2});
        return;
    }
    this.label1.Text = (str1 == string.Empty) ? this.label1.Text : str1;
    this.label2.Text = (str2 == string.Empty) ? this.label2.Text : str2;
}

Is this not the proper way to go about this? Is there something I need to add to make sure it doesn’t try to perform updates on the UI while the app is closing?

  • 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-06-14T13:07:49+00:00Added an answer on June 14, 2026 at 1:07 pm

    The ObjectDisposedException you are receiving is most likely due to letting the Form close while having Invokes (in the queue) that haven’t yet completed. You’ll either need to allow the Invokes to complete before allowing the form to close or you’ll have to handle the ObjectDisposedException.

    See:

    • ObjectDisposedException on call to Form's Invoke when it hasn't been Disposed
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a very simple PrototypeJS class that looks like this: var
Lets say I have a class A that is fairly simple like this -
Assume I have a class that looks like this: class Sample { public string
I have this small class called City that simply holds some information about a
I have this simple class public class Position{ int x; int y; Position(int x,int
I have this very simple C++ class: class Tree { public: Node *head; };
I have this simple test project just to test the IncludeExceptionDetailInFaults behavior. public class
I have this simple example: using System; using System.Collections.Generic; namespace ConsoleApplication1 { class Program
i have this class called MemoryManager, it is supposed to implement a simple smart
If I have a simple class setup like this: class MyClass { private string

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.