Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Help with "Invoke or BeginInvoke cannot be called on a control until the window handle has been created."

Help with "Invoke or BeginInvoke cannot be called on a control until the window handle has been created."

Scheduled Pinned Locked Moved C#
helpquestionannouncement
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    turbosupramk3
    wrote on last edited by
    #1

    Hi. What I'm trying to accomplish is to call this class, pass some controls and values and then have the new object update the existing control. Help with this would be appreciated? Maybe it is not possible since I cannot pass the handle value to the class? The error is a little misleading as the control is already created?

    private void btnGroupsForUserTest_Click(object sender, EventArgs e)
    {

      progressBarControl pbarcontrol = new progressBarControl();
      pbarcontrol.pbarIncrementValue = 1;
      pbarcontrol.pbarMaximum = 100;
      pbarcontrol.pbarThreadSleepIncrement = 250;
      pbarcontrol.pbarObject = pBarGroupsForUser;
      pbarcontrol.pbarLabel = lblGroupsForUserStatus;
    
      progressBarIncrementer = new Thread(new ThreadStart(pbarcontrol.pbarIncrementFunction));
      progressBarIncrementer.IsBackground = true;
      progressBarIncrementer.Start();
      }
    

    public class progressBarControl : FormGroupMemberShipCheckingTool
    {
    public ProgressBar pbarObject;// { get; set; }
    public Label pbarLabel;// { get; set; }

    public int pbarMaximum { get; set; }
    public int pbarIncrementValue { get; set; }
    public int pbarThreadSleepIncrement { get; set; }
    
    public void pbarIncrementFunction()
    {
    
        int incrementValue = pbarIncrementValue;
        do
        {
            this.Invoke((MethodInvoker)delegate()
            {
                if (incrementValue < pbarMaximum)
                {
                    pbarObject.Value = incrementValue;
                    pbarLabel.Text = incrementValue.ToString() + "% complete";
                    Application.DoEvents();
                }
            });
            incrementValue++;
            Thread.Sleep(pbarThreadSleepIncrement);
        } while (incrementValue < pbarMaximum);
    }
    

    }

    Richard DeemingR 1 Reply Last reply
    0
    • T turbosupramk3

      Hi. What I'm trying to accomplish is to call this class, pass some controls and values and then have the new object update the existing control. Help with this would be appreciated? Maybe it is not possible since I cannot pass the handle value to the class? The error is a little misleading as the control is already created?

      private void btnGroupsForUserTest_Click(object sender, EventArgs e)
      {

        progressBarControl pbarcontrol = new progressBarControl();
        pbarcontrol.pbarIncrementValue = 1;
        pbarcontrol.pbarMaximum = 100;
        pbarcontrol.pbarThreadSleepIncrement = 250;
        pbarcontrol.pbarObject = pBarGroupsForUser;
        pbarcontrol.pbarLabel = lblGroupsForUserStatus;
      
        progressBarIncrementer = new Thread(new ThreadStart(pbarcontrol.pbarIncrementFunction));
        progressBarIncrementer.IsBackground = true;
        progressBarIncrementer.Start();
        }
      

      public class progressBarControl : FormGroupMemberShipCheckingTool
      {
      public ProgressBar pbarObject;// { get; set; }
      public Label pbarLabel;// { get; set; }

      public int pbarMaximum { get; set; }
      public int pbarIncrementValue { get; set; }
      public int pbarThreadSleepIncrement { get; set; }
      
      public void pbarIncrementFunction()
      {
      
          int incrementValue = pbarIncrementValue;
          do
          {
              this.Invoke((MethodInvoker)delegate()
              {
                  if (incrementValue < pbarMaximum)
                  {
                      pbarObject.Value = incrementValue;
                      pbarLabel.Text = incrementValue.ToString() + "% complete";
                      Application.DoEvents();
                  }
              });
              incrementValue++;
              Thread.Sleep(pbarThreadSleepIncrement);
          } while (incrementValue < pbarMaximum);
      }
      

      }

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      The progressBarControl control has been created, but the window handle for the control has not. You create a new instance of the control, but never show it anywhere, so it never creates a window. Try using pbarObject.Invoke instead.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      T 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        The progressBarControl control has been created, but the window handle for the control has not. You create a new instance of the control, but never show it anywhere, so it never creates a window. Try using pbarObject.Invoke instead.


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        T Offline
        T Offline
        turbosupramk3
        wrote on last edited by
        #3

        Doh! Thank you, that worked!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups