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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:55:39+00:00 2026-06-13T11:55:39+00:00

The code that I’m working on at the moment had a method that ran

  • 0

The code that I’m working on at the moment had a method that ran in the UI thread. But it was taking a long time, so I decided to put it in a BackgroundWorker. The code was normally editing the UI and when I changed the thread there came the problem of editing the controls in the UI thread. So what I did was to make the method report it’s state, and change the UI in ProgressChanged event. To report the progress, this method takes one object named “userState”, but for my purposes, I had to report more than one object. So I chose to do the following:

        // Create a dictionary to keep method state for reporting.
        // "state" item represents a state type; "error", "update", "success".
        // "message"d item represents the message associated with the state.
        // "result" item represents the function result.
        // "invisiblecolumns" item represents the invisible columns this method finds.
        var methodState = new Dictionary<string, object> { { "state", "update" }, { "message", string.Empty }, 
                                                           { "result", null }, { "invisiblecolumns", null } };

But I’m not sure if this is a good way to do it. What would your suggestion be as to how to handle the reporting process in a background worker? What is a good practice? And is what I did a good workaround?

  • 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-13T11:55:40+00:00Added an answer on June 13, 2026 at 11:55 am

    I think it’s better to create a class for your operation result (also I’d give this class more descriptive name, thus you are performing some specific operation):

    public class OperationResult
    {
        public OperationResult(OperationState state, string message = "")
        {
            State = state;
            Message = message;
        }
    
        public OperationState State { get; private set; }
        public string Message { get; private set; }
        // property for "result"
        // property for "invisiblecolumns
    }
    
    public enum OperationState
    {
        Update,
        Success,
        Error
    }
    

    Your code will be much more readable, maintainable, and you’ll have IntellySense support. Compare:

     var result = (Dictionary<string, object>)e.UserState;
     if (result["slate"] == "update") // yep, misprint
        // do something
     labelMsg.Text = result["message"];
     // do you remember names of other entries?
    

    With

     var result = (OperationResult)e.UserState;
     if (result.State == OperationState.Update)
        // do something
     labelMsg.Text = result.Message;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code that had been working is suddenly not. Printing works fine in all browsers
The code that I am working on is changing my temporary variables, and I
The code that I am working with has tons of style that I want
My code that give long month name instead short name: var monthShortName=$.datepicker.formatDate('MM d, yy',
I have code that generates a List<string[]> variable but can't quite figure out how
Some code that I had that used attr_accessor_with_default in a rails model is now
I have this code that I have written in Ruby, but when trying to
I wrote a php code that display error in red color. But somehow, this
The code that I'm acttualy having the problem with is very long, so I
Sample code that shows how to create threads using MFC declares the thread function

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.