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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:41:55+00:00 2026-05-26T11:41:55+00:00

I have a problem about using multithreading in c#. I have a complex computing

  • 0

I have a problem about using multithreading in c#. I have a complex computing thing that must run on the main thread means it must run on the main window.

My program runs like this :

  • First it will open a new window and user can input parameter
  • Then it will run a complex computing that must run in the main thread ( i can’t change this, i’m using library that prevent call the computing thing in different thread, if i’m using different thread it will come with an exception).
  • When the simulation run, it will also open a new window that monitoring the computing, it will also plot the graphic for it, and i need it to be real time.

Problem: Since the long time complex computing is running on the main thread, the monitoring window will be hang and not responding. Is there any tricky way to solve this? Can i use different thread to run the monitoring window? the main form is okay for not responding, but not okay for monitoring window. Here i put some code that resembles my program, not my real program, but the flow is the same.

Main Form(main thread that will run the computing thing,and input parameter from user)

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        compute c = new compute();
        c.computing();
    }
}

Graph Form (Monitoring Graph that will plot chart, needed to be real time)

    public graphic()
    {
        InitializeComponent();
    }

    private void label1_Click(object sender, EventArgs e)
    {

    }

    public void updateLabel(int count)
    {
        label1.Text = "Current i value:  " + count;
    }

Compute class (doing the computing thing)

class compute
{
    delegate void writeToForm(int i);
    graphic g = new graphic();

    public compute()
    {
        g.Show();
    }
    public void computing()
    {
       //THIS PART MUST RUN ON THE MAIN THREAD, DON'T MAKE IT ON THE OTHER THREAD
       //IT IS A MUST
        int count = 0;
        //THIS IS THE LONG TIME COMPUTING THING
        for (int i = 0; i < 100; i++)
        {
            count += i;
            updateLabel(count);
            Thread.Sleep(2000);
        }
    }

    private void updateLabel(int count)
    {
        if (g.InvokeRequired)
        {
            g.Invoke(new writeToForm(updateLabel), new object[] { count });
            return;
        }
        g.updateLabel(count);
    }
}

I can’t do anything about the method must run in the main thread, i’m using library that prevent its method to be ran from other method, thanks..

  • 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-26T11:41:56+00:00Added an answer on May 26, 2026 at 11:41 am

    A possible workaround would be to write your monitoring form in another program, which can be launched by your main program before the computing method is executed. Yes, your main form will still hang (but you say this isn’t a problem?).

    You could communicate with your main application, possibly by opening a local TCP connection (which can run on a different thread without a problem). This could send commands to the monitoring application (or any other connected TCP clients if you wish), which would receive these and use the Control.Invoke method to update the UI.

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

Sidebar

Related Questions

I have a little problem about using jQuery (I really do not know jQuery
I am using MFC CFile Seek function. I have a problem about Seek out
I have got a performance problem about TextField.htmlText +=msg .And I know that TextField.appendText(msg)
So I have a problem that I don't really know how to go about.
I need guideline about using of robots.txt problem is as following. I have one
We have some performance problems with one of our applications. I thought about using
I have a problem about div position relative alignment. I want the second div
I have hit upon this problem about whether to use bignums in my language
I have got a strange problem about in_array recently which I cannot understand. e.g.
i have a problem. i want to get info about my string have other

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.