Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue while invoking a form from another using System.Window.Forms.Invoke(delegate)
    primarykey
    data
    text
    <p>I have two forms and 1 singleton class. I am initalizing the singleton class in btn_A_Click of formA.</p> <pre><code>public partial class frmA : Form { public frmA() { InitializeComponent(); frmB frmB; } private void btn_A_Click(object sender, EventArgs e) { SessionMgmt.GetInstance().StartFormB(); } } </code></pre> <p>This is my singleton class and here I am trying to use Forms.Invoke() method. </p> <pre><code>public class SessionMgmt { static SessionMgmt _sessinMgr; frmB frB; private SessionMgmt() { frB = new frmB(); } public static SessionMgmt GetInstance() { if (_sessinMgr != null) return _sessinMgr; else { _sessinMgr = new SessionMgmt(); return _sessinMgr; } } public bool StartFormB() { frB.Invoke(new EventHandler(DisplayFrmB)); return true; } private void DisplayFrmB(Object o, EventArgs e) { frB.Visible = true; frB.Refresh(); } </code></pre> <p>}</p> <p>This is my formB.</p> <pre><code>public partial class frmB : Form { } </code></pre> <p>But from the <code>frB.Invoke(new EventHandler(DisplayFrmB));</code> method it throws the following exception:</p> <blockquote> <p>Invoke or BeginInvoke cannot be called on a control until the window handle has been created.</p> </blockquote> <p>I can't figure out the issue, please help or advice me if I miss anything.</p> <p><strong>EDIT</strong></p> <p>The following structure is the way my current project is displaying the next form. It was done by VB.NET and I need to use similar kind of thing in the new project which uses C#. I saw the Invoke function which points to an event and then to a function. In that function it just makes the Form.Visible=true and Form.Refresh. But for understanding I just tried a POc and followed the same steps ,but it is not yet solved.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload