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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:56:26+00:00 2026-06-16T22:56:26+00:00

I have created a console application. I want to make the label (on the

  • 0

I have created a console application. I want to make the label (on the form) display whatever I type in the console, but the console hangs when I run the form.

code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ConsoleApplication1
{
    class Program
    {
        Label a;
        static void Main(string[] args)
        {
            Form abc = new Form(); 
            Label a = new Label();
            a.Text = "nothing";
            abc.Controls.Add(a);
            Application.Run(abc);
            System.Threading.Thread t=new System.Threading.Thread(Program.lol);
            t.Start();


        }
        public static void lol()
        {
            Program p = new Program();
            string s = Console.ReadLine();
            p.a.Text = s;
            lol();
        }


    }
}
  • 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-16T22:56:27+00:00Added an answer on June 16, 2026 at 10:56 pm

    Application.Run will block until the form has closed. So you should call that on a separate thread.

    However, your UI will then be executing on that separate thread – and you mustn’t “touch” a UI element from a thread other than the UI thread, so after calling Console.ReadLine(), you’ll need to use Control.Invoke or Control.BeginInvoke to make changes in the UI.

    Additionally, you’re currently declaring a local variable called a, but never assigning a value to Program.a.

    Here’s a complete version which works:

    using System;
    using System.Threading;
    using System.Windows.Forms;
    
    class Program
    {
        private Program()
        {
            // Actual form is created in Start...
        }
    
        private void StartAndLoop()
        {
            Label label = new Label { Text = "Nothing" };
            Form form = new Form { Controls = { label } };
            new Thread(() => Application.Run(form)).Start();
            // TODO: We have a race condition here, as if we
            // read a line before the form has been fully realized,
            // we could have problems...
    
            while (true)
            {
                string line = Console.ReadLine();
                Action updateText = () => label.Text = line;
                label.Invoke(updateText);
            }
       }
    
        static void Main(string[] args)
        {
            new Program().StartAndLoop();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a console application and have it working the way I want
I have created a console application in .Net 2.0 (C#) and want to create
I have created a small chatting application in C#, and started as a Console
I have a console application and I want to deploy/share it using some msi/setup.exe
I am new in C# console application. I have a question: I want to
I created a console Application which hosts the service... now i want to take
I have created an application in Rails, I want to create a puccuentas model:
I have a console application from which I create a window. I can render
I have written a little console application that uses s#arp. I can create an
I have a new Codeblocks install with mingw32 compiler. Created new c++ console project

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.