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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:59:18+00:00 2026-06-16T00:59:18+00:00

Hello im pretty new to c# just downloaded VS2012 and created my new Application,

  • 0

Hello im pretty new to c# just downloaded VS2012 and created my new Application, but im getting a really strange Exception, I guess its my fault but again im really new to this

the exception occours when closing form2 that form1 created. this only occurs when an object its placed on form2.

I just got 2 forms with a button on each, button on form1 calls form2, when form2 is closed I show again form1, after a few seconds it throws InvalidOperationException on line base.Dispose

here is the code that trhows the exception

protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing); // here is the exceptjion
        }

Here is form1

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

        private void button1_Click(object sender, EventArgs e)
        {
            var frm = new Form2(this);
            frm.Show(this);
            this.Hide();
        }
    }

Here is form2

public partial class Form2 : Form
{
    private Form frm;

    public Form2(Form frm) : this()
    {
        this.frm = frm;
    }

    public Form2()
    {
        InitializeComponent();
    }

    private void Form2_FormClosing(object sender, FormClosingEventArgs e)
    {
        frm.Show();
        this.Close();
    }
}

Here is the stacktrace

No se controló System.InvalidOperationException
  HResult=-2146233079
  Message=Operación no válida a través de subprocesos: Se tuvo acceso al control 'button1' desde un subproceso distinto a aquel en que lo creó.
  Source=System.Windows.Forms
  StackTrace:
       en System.Windows.Forms.Control.get_Handle()
       en System.Windows.Forms.Control.get_InternalHandle()
       en System.Windows.Forms.Control.DestroyHandle()
       en System.Windows.Forms.Control.Dispose(Boolean disposing)
       en System.Windows.Forms.ButtonBase.Dispose(Boolean disposing)
       en System.ComponentModel.Component.Dispose()
       en System.Windows.Forms.Control.Dispose(Boolean disposing)
       en System.Windows.Forms.Form.Dispose(Boolean disposing)
       en PruebaExceocion.Form2.Dispose(Boolean disposing) en c:\Users\Alex\Documents\Visual Studio 2012\Projects\PruebaExceocion\PruebaExceocion\Form2.Designer.cs:línea 20
       en System.ComponentModel.Component.Dispose()
       en System.Windows.Forms.Form.WmClose(Message& m)
       en System.Windows.Forms.Form.WndProc(Message& m)
       en System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       en System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       en System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  InnerException: 
  • 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-16T00:59:19+00:00Added an answer on June 16, 2026 at 12:59 am

    If you just simply program with 2 forms, then calling one from the other’s button can be done also simply like

        //On form1
        private void button1_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            f2.Show();
        }
    

    And no more, you can close the second form whenever you want without any error (I tested this on vs12). It will create a new instance of the Form2 with each button click.
    So it becomes a bit trickier if you only want one and the same instance of form2 displayed with each click.

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

Sidebar

Related Questions

Hello I am pretty new to C# so I'm not entirely sure what I'm
Hello! I've been programming for a long time but just started developing for android,
I'm just starting to learn JSP (and I'm pretty new to Java in general),
I'm pretty new to J2ME development scene. And for that matter, have just recently
I'm pretty new to Android development, so I decided starting with simple hello world
I'm pretty new to regular expressions, but I'm sure a regex would give me
So I'm new to jQuery and JSON but this is pretty straight forward and
I'm pretty new to cocoa and Xcode, I've done some basic C coding, but
I'm pretty new to Scala, but I thought that one of the strengths of
I have been programming C for a while (but still pretty new to C)

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.