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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:57:56+00:00 2026-06-11T12:57:56+00:00

Edit for better understanding… I have a Form1.cs file and a separate Class.cs file.

  • 0

Edit for better understanding…

I have a Form1.cs file and a separate Class.cs file.

In Form1 I have a bgWorker that calls Class.myFunc(), this does three foreach loops, each loop return some values such as string ClientName, or string ClientOrder.

I want to return these values from Class.myFunc to bgWorker (which is inside Form1, remember) and insert them into a ListView, Textbox, or whatever.

So the problem is: How I return string values from Class.myFunc to BgWorker?

I hope someone can help me with this…

Form1.cs

void bgWorker_DoWork(object sender, DoWorkEventArgs e)
{
    ControlsHelper.ControlInvike(listProcess, () => listProcess.Items.Add("Current").Name = "item1");
            myOtherClass cp = new myOtherClass();
            cp.myFunc();
}

Class.cs

public void myFunc()
{
    foreach (string Client in Clients)
    {
           // Do something
           // Return Client and insert into listview, richtextbox, W/E
    }
} 
  • 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-11T12:57:57+00:00Added an answer on June 11, 2026 at 12:57 pm

    To expand on Daniel Hilgarth’s answer: if the BGW doesn’t exist in the context of Class.cs can you not pass it in as a parameter so that you can update your progress. In your DoWork signature the object sender is the BGW you want to cast as BackgroundWorker to send into myFunc.

    So you’d have

    public void myFunc(BackgroundWorker bgw)
    {
        foreach (string Client in Clients)
        {
           // Do something
           // Return Client and insert into listview, richtextbox, W/E
    
           var returningObjects = List<string>();  //I assume this will be a list of strings based on your question.
           returningObjects.Add(ClientName);
           returningObjects.Add(ClientOrder);
           returningObjects.Add(Client3rdThing);
    
           bgw.ReportProgress(0,returningObjects)
        }
    } 
    

    An even better than using a generic List<string> you could make your own class which has all the items you need then you can call them explicitly instead of referring to a list index.

    void bgWorker_DoWork(object sender, DoWorkEventArgs e)
    {
        BackgroundWorker bgw = sender as BackgroundWorker;
        ControlsHelper.ControlInvike(listProcess, () => listProcess.Items.Add("Current").Name = "item1");
                myOtherClass cp = new myOtherClass();
                cp.myFunc(bgw);
    }
    

    Then in your ProgressChanged event handler

    private void bgWorker_ProgressChanged(object sender,
        ProgressChangedEventArgs e)
    {
       //Set the  e.UserState to whatever you need. It is of type Object.
        var returnedObjects = e.Userstate as List<string>;
        if(returnedObjects != null)
        {
            //do stuff with each of your returnedObjects[i];
        }
    
    }
    

    To ensure thread safety I use this extension method for controls. It’s really great having this logic wrapped up in an extension method. You don’t need to think about the Invoke structure whenever you need to call it, you just call it.

    And be sure to tie it all together when you instantiate your BackgroundWorker using

    bgWorker.ProgressChanged += new ProgressChangedEventHandler(bgWorker_ProgressChanged);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is an edit of the original post now that I better understand the
EDIT: thanks for all the speedy responses, I have a much better understanding of
Here is jsFiddle for better understanding: http://jsfiddle.net/BzYcZ/ I have some div that have scrollbars.
EDIT: I completely reworked this question to reflect my better understanding of the problem
EDIT NOTE I am rewording this question entirely now that I have a bit
EDIT: I'd better rephrase: How can I shift the GET-implementation of a Class property
I have a problem trying to edit. I work with Areas for better management
EDIT: See my answer below--> I am wanting to have a view that when
To solve a problem (and better my understanding of multitasking) I have written a
I'm trying to get a better understanding of how endpoints work. I've read this

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.