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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:09:40+00:00 2026-05-12T08:09:40+00:00

Right now, I have a windows application (C#) that spits out long running reports.

  • 0

Right now, I have a windows application (C#) that spits out long running reports. Each report grabs some information from the UI to constrain the reports. Of course, the report creation happens on a background thread and I need to properly invoke the various controls to get things like selected indexes and values. But I don’t think my code looks good and was hoping there was a better pattern. Because there are so many requests to controls, I made generic delegates for each type that would be returned:

private delegate string StringDelegate();
private delegate int IntDelegate();

Further down, there are various instantiations of these delegates:

private StringDelegate GetYearSelectedItem = new StringDelegate(cmbYearAsync);

YearAsync looks like this:

private string cmbYearAsync() {
    return cmbYear.SelectedItem.ToString();
}

And finally, in code that is on a background thread, this is how I get the values:

cmbYear.Invoke(GetCmbYearSelectedItem);

Is there a cleaner way of getting these values from a separate thread?

  • 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-12T08:09:40+00:00Added an answer on May 12, 2026 at 8:09 am

    Assuming you want to go with the threaded design (perhaps you want the background threads to report partial results to the UI as they run?), if you have C# 3 you can certainly neaten it up a little. Some people find an extension method like this helpful:

    public static class ControlExtensions
    {
        public static T Invoke<T>(this Control ctrl, Func<T> func)
        {
            if (ctrl.InvokeRequired)
                return (T) ctrl.Invoke(func);
    
            return func();
        }
    }
    

    As well as checking whether the call needs to be marshalled, it also makes the delegate parameter typesafe. So you can write:

    string selected = comboBox1.Invoke(() => comboBox1.SelectedItem.ToString());
    

    No need to pre-declare all that other stuff. Just write the usual code you’d write but inside that lambda pattern.

    You can write a similar extension method that takes Action instead of Func<T>, and returns void, for operations that don’t need a return value.

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

Sidebar

Ask A Question

Stats

  • Questions 271k
  • Answers 271k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If the list is sorted, you can use groupby from… May 13, 2026 at 1:44 pm
  • Editorial Team
    Editorial Team added an answer As a string, no. As an integer, %d. Unless you… May 13, 2026 at 1:44 pm
  • Editorial Team
    Editorial Team added an answer I would recommend just inheriting the Image class and adding… May 13, 2026 at 1:44 pm

Related Questions

I have a windows service written in C# .NET framework 3.5 and would like
I've looked into COM servers and Windows services but I'm not sure what best
I've written a Windows desktop application that works with Sqlite very nicely. It was
Does Java 6 consume more memory than you expect for largish applications? I have

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.