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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:39:47+00:00 2026-06-02T03:39:47+00:00

I have two WinForms applications and I need to add text to TextBox in

  • 0

I have two WinForms applications and I need to add text to TextBox in Application1 from Application2. I’ve successfully done this using named pipes and WCF. I can successfuly call a method in Application1 from Application2 but I’m getting either “Invoke or BeginInvoke cannot be called on a control until the window handle has been created.” error or the textbox is not updated at all.

Here’s my basic code. GetMessage is called by Application2. This one doesn’t update TextBox at all:

public void GetMessage(string msg)
{
    UpdateTextbox(msg);
}

private void UpdateTextbox(string msg)
{
    this.textBox1.Text += msg + Environment.NewLine;
}

This one throws Invoke error:

public void GetMessage(string msg)
{
    Action a = () => UpdateTextbox(msg);
    textBox1.BeginInvoke(a);
}

I tried to cheat my way by forcing creation of the handle with this, but it doesn’t update TextBox either:

public void GetMessage(string msg)
{
    IntPtr handle = textBox1.Handle;
    Action a = () => UpdateTextbox(msg);
    textBox1.BeginInvoke(a);
}

What should I do?

  • 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-02T03:39:48+00:00Added an answer on June 2, 2026 at 3:39 am

    Solved the problem thanks to this answer.

    The problem is that the TextBox of the Form1 was on another instance of the Form1. Observe this code from Application1.Form1 which starts the named pipe service:

    private void Form1_Load(object sender, EventArgs e)
    {
        ServiceHost host = new ServiceHost(typeof(Form1), new Uri[] { new Uri("net.pipe://localhost") });
        host.AddServiceEndpoint(typeof(ISmsService), new NetNamedPipeBinding(), "PipeReverse");
        host.Open();
    }
    

    If I am understanding it right, this starts an instance of Form1. Thus, when Application2 calls Application1.GetMessage, it calls ServiceHost-instance-Form1.GetMessage.

    To access main instance of Form1 I changed my code to this:

    public Form1()
    {
        InitializeComponent();
    
        if (mainForm == null)
        {
            mainForm = this;
        }
    }
    
    private static Form1 mainForm;
    public static Form1 MainForm
    {
        get
        {
            return mainForm;
        }
    }
    
    private void UpdateTextbox(string msg)
    {
        MainForm.textBox1.Text += msg + Environment.NewLine;
    }
    

    It works correctly now..

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

Sidebar

Related Questions

I have two separate .NET applications, one server and another WinForms. WinForms app has
I have two different WinForms applications, AppA & AppB. Both are running .NET 2.0.
I have a variety of small C# winforms applications (though this should apply equally
I have made a simple test application for the issue, two winforms each containing
In Winforms you can have two controls tied to the same datasource in a
I need to add a second DataTable from our app's main DataSet into a
I'm using NotifyIcon (System tray icon) in my WinForms application. I also have a
I have an architectural question, we need to develop information system with two frontends:
Let’s say that I have two C# applications - game.exe (XNA, needs to support
I have a Winforms DataGridView in my application. I've two checkbox columns along with

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.