CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2010
    Posts
    23

    invoke a form , from a thread

    hey guys

    how do i can invoke a form, from a thread, which in that thread i have a

    while(true){}

    in this while i want to show a form in some circumstance, i did like this
    Code:
    {
               .
               .
               .
               .
               //the conditions to call search form is alright here 
               search frm=new search();
               frm.Invoke(new _Form(_Form_1), new object[] { frm });
               .
               .
               .
               .
    }
    
            delegate void _Form(Form frm);
            void _Form_1(Form frm)
            {
                frm.Show();
            }
    but this gives me this exception, which i not know what is?

    $exception {"Invoke or BeginInvoke cannot be called on a control until the window handle has been created."} System.Exception {System.InvalidOperationException}

    how to solve this?

    tnx in advance

  2. #2
    Join Date
    Nov 2010
    Posts
    34

    Re: invoke a form , from a thread

    try a format like this, you'll have to pull out some of the extra, but this forces the re-calling of the invoke if the form is not ready (or perhaps not created as in your case)

    delegate void PassRT(string line, int num);
    public void RT1(string line, int num)
    {
    if (richTextBox1.InvokeRequired)
    {
    PassRT x = new PassRT(RT1);
    richTextBox1.Invoke(x, new object[] { line, num });
    }
    else
    {
    if (num == 1)
    {
    richTextBox1.Text = richTextBox1.Text + "\n" + line;
    richTextBox1.SelectionStart = richTextBox1.Text.Length;
    richTextBox1.ScrollToCaret();
    }
    else
    {
    richTextBox1.Text = richTextBox1.Text + line;
    richTextBox1.SelectionStart = richTextBox1.Text.Length;
    richTextBox1.ScrollToCaret();
    }
    }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured