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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:42:21+00:00 2026-05-23T16:42:21+00:00

So, I took over an existing WinForms app recently. We need to change it

  • 0

So, I took over an existing WinForms app recently. We need to change it to something that runs in the system tray, but still pops up the form when a user wants to. No problem. As per this question: Mutex is being used to ensure only one copy of the app is running

The app has 3 main components: the custom application context (myContext) which handles all the system stray stuff. myContext creates an instance of a class called Gozer (myGozer). Gozer does all the real work. It performs a series of operations on a timed interval (check network status, if we have a connection it then does a few other things. It also plays Global Thermo-nuclear War with itself for fun). It let’s everybody else know what’s going on via a series of events. When myForm is opened, myContext is passing myGozer in.

It’s when I open myForm that I start bumping into all sorts of Cross-Threading issues (any time a control is used in some way. Like manipulating myListView). What I’m not clear on is the best way to deal with this. I know very little about threading. I do not have a super large brain that can come to understand threading in 30 seconds. And I don’t have anyone around I can eat to absorb their superior knowledge of threading.

According to this question, I can simply check someControl.InvokeRequired and then invoke method in question via a delegate. This works. But now I’m facing dropping a bunch of code in front of every time I need to deal with a control, which sets off some likely poorly-calibrated alarm bells in my head. I also discovered a problem when exiting the application from the form; this causes another Cross-Threading exception back in myContext. I am not sure it’s appropriate to exit the app from myForm any longer, but what other cross-threading madness is awaiting me at this time? I feel like I’m setting myself up for a lot of side-effect induced headaches.

I guess I’m really worried about creating a bunch of potential issues down the road. Or being asked to expand Gozer’s capabilities and then creating further issues when that requires work in myForm. Or finding that opening and closing myForm while running creates a bunch of additional cross-threading issues. Or that the app will cause everything to explode.

Is there something else I should be considering or missing?

Note: this is for a .net 2.0 app, so Jethro’s solution will not work here. That said, since it’s not that many places I have to write InvokeRequired logic, I’m just going to do that. I’m pretty sure I’m going to get to upgrade this to .net 3.5 in the next year and the suggested class below is how I’ll be handling he issue. I’m marking it as the answer as a result.

  • 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-23T16:42:21+00:00Added an answer on May 23, 2026 at 4:42 pm

    Here’s an extension you can use. Can’t recall were I picked it Up.

    Call it like this.

    this.InvokeEx(p=> p.txtbox.Text = "Rad");
    
    
    public static class ControlExtensions
    {
        public static TResult InvokeEx<TControl, TResult>(this TControl control,
                                                    Func<TControl, TResult> func)
            where TControl : Control
        {
            return control.InvokeRequired
                    ? (TResult)control.Invoke(func, control)
                    : func(control);
        }
    
        public static void InvokeEx<TControl>(this TControl control,
                                                Action<TControl> func)
            where TControl : Control
        {
            control.InvokeEx(c => { func(c); return c; });
        }
    
        public static void InvokeEx<TControl>(this TControl control, Action action)
            where TControl : Control
        {
            control.InvokeEx(c => action());
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just took over a clients flex project and I can't get the app
I took an existing MySQL database, and set up a copy on a new
I have a list of elements describing events that took place at some time,
For trying out some pointer stuff, I made an instance variable in an existing
First of all I have to admit that my programming skills are pretty limited
I have a simple task. I have an existing project with a web service
I was trying to retrieve binary data over HTTP for my Flex application, and
I have a simple program that uses TcpClient and SslStream to write data to
I'm currently working on creating an environment to test performance of an app; I'm
I'm trying to tune the performance of my application. And I'm curious what methods

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.