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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:01:40+00:00 2026-05-31T12:01:40+00:00

I finished my little project that does some heavy lifting. i realized in this

  • 0

I finished my little project that does some heavy lifting. i realized in this short calculation time, my GUI freezes. So I did some research and I found this => http://www.codeproject.com/Articles/4381/Threading-out-tasks-in-a-C-NET-GUI

I started to implement this is my project, but i realized that this particular implementation does not work in my project.

In my project i have many classes and one ” manager ” that controls all other classes. If i initilize this Manager class , it already does the heavy lifting in the constructor.

To my Question :

How do i start a new thread with a contructor ?

private void fileWatcher_Changed(object sender, System.IO.FileSystemEventArgs e)
        {


            if (System.IO.File.Exists(e.FullPath) == true)
            {

                Manager mgr = new Manager(e, handreader); // here starts the heavy lifting
                Thread mgrThread = new Thread(new ThreadStart(mgr));  // what to do ?
                sl.Text = mgr.test();
                txtLog.Text = mgr.output();


            }
        }

EDIT :
okay i decided to recode my program. now the heavy lifting is in one function but i think i made a mistake.

the whole program looks like this :

 private void fileWatcher_Changed(object sender, System.IO.FileSystemEventArgs e)
        {


            if (System.IO.File.Exists(e.FullPath) == true)
            {
                Manager mgr = new Manager(e, handreader, txtLog, sl);
                //sl.Invoke(new MethodInvoker(mgr.test));
                sl.Invoke(new MethodInvoker(mgr.test)); // first try 
                Thread mgrThread = new Thread(new ThreadStart(mgr.test)); // second try

            }
        }

the sl.Invoke(new MethodInvoker(mgr.test)); // first try works but it still freezes my GUI.

Thread mgrThread = new Thread(new ThreadStart(mgr.test)); // second try

and this line does nothing.

my test function :

 public void test()
    {
        StringBuilder builder = new StringBuilder();
        foreach (PlayerController pc in fm.lPc)
        {
          Range  range = new Range(handReader.hand, handReader.handversus, pc);
          builder.Append(pc.getHeroCardsSimple()+" vs 100% range =   "+range.vsRange()+"\r\n");
        }
        sl.Text = builder.ToString();
    }
  • 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-31T12:01:41+00:00Added an answer on May 31, 2026 at 12:01 pm

    You should use a different approach for this. Your constructor is still being invoked on the GUI thread.

       

        Func<Manager> asyncConstructor;
        private void fileSystemWatcher1_Changed(object sender, System.IO.FileSystemEventArgs e)
        {
            asyncConstructor = new Func<Manager>(() => new Manager());
    
            asyncConstructor.BeginInvoke(ManagerConstructed, null);
        }
    
        private void ManagerConstructed(IAsyncResult result)
        {
            Manager mgr = asyncConstructor.EndInvoke(result);
            //we can only access form controls from the GUI thread, 
            //if we are not on the gui thread then
            //do the changes on the gui thread.
            if (this.InvokeRequired)
            {
                this.Invoke(new Action(() =>
                {
                    sl.Text = mgr.test();
                    txtLog.Text = mgr.output();
                }));
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to get this little project I'm doing finished, but for some
Just finished reading this blog post: http://www.skorks.com/2010/03/an-interview-question-that-prints-out-its-own-source-code-in-ruby/ In it, the author argues the case
Hi I quite finished my third app with Titanium. This time is not for
I am new to Java, I just finished my first little project, and I
I'm a little stuck. I have almost finished this code but after trying to
I've been working on a (nearly finished) Javascript project for a little over 14
Just finished a little app that I want to distribute and at the moment
I'm writing a little DirectX model viewer. I just finished writing my scene manger.
I finished building an app that allows beaming of photos, contacts and text clips
I finished my website and uploaded it to my webhost, but i get 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.