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. Mysterious behaviour (freezing)

Mysterious behaviour (freezing)

Scheduled Pinned Locked Moved C#
graphicsquestionannouncement
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.
  • G Offline
    G Offline
    GuntherR
    wrote on last edited by
    #1

    :confused::confused::confused: If somebody could make sense of the behaviour of the following code, I'd be really happy. On the second line, either #define CRASH to have it crash or don't to have it, well, not crash. Then just pick the menu items sequentially from 1 to 4. The only difference is that in the crashing version, a UserControl is added as a control to a Panel instead of directly to a Form... After closing the form created in step 4, the application freezes, sometimes terminates with an ObjectDisposedException ... Cheers, Gunther :omg: ------------- CODE STARTS HERE ------------- // define "CRASH" to have it crash when you go from 1 to 4 ... #define CRASH using System; namespace TestApp { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { [STAThread] static void Main() { System.Windows.Forms.Application.Run(new Form1()); } private System.Windows.Forms.Panel panel1; public Form1() { this.panel1 = new System.Windows.Forms.Panel(); this.SuspendLayout(); // // Menu // this.Menu = new System.Windows.Forms.MainMenu(); System.Windows.Forms.MenuItem mi = new System.Windows.Forms.MenuItem("Crashing!?"); this.Menu.MenuItems.Add(mi); mi = new System.Windows.Forms.MenuItem("1. Create Control"); mi.Click += new EventHandler(this.Create_Click); this.Menu.MenuItems[0].MenuItems.Add(mi); mi = new System.Windows.Forms.MenuItem("2. Display Dialog"); mi.Click += new EventHandler(this.Dialog_Click); this.Menu.MenuItems[0].MenuItems.Add(mi); mi = new System.Windows.Forms.MenuItem("3. Destroy Control"); mi.Click += new EventHandler(this.Destroy_Click); this.Menu.MenuItems[0].MenuItems.Add(mi); mi = new System.Windows.Forms.MenuItem("4. Display Dialog"); mi.Click += new EventHandler(this.Dialog_Click); this.Menu.MenuItems[0].MenuItems.Add(mi); mi = new System.Windows.Forms.MenuItem("-"); this.Menu.MenuItems[0].MenuItems.Add(mi); mi = new System.Windows.Forms.MenuItem("Quit"); mi.Click += new EventHandler(this.Quit_Click); this.Menu.MenuItems[0].MenuItems.Add(mi); // // panel1 // this.panel1.AutoScroll = true; this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; this.panel1.Location = new System.Drawing.Point(0, 0); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Siz

    J 1 Reply Last reply
    0
    • G GuntherR

      :confused::confused::confused: If somebody could make sense of the behaviour of the following code, I'd be really happy. On the second line, either #define CRASH to have it crash or don't to have it, well, not crash. Then just pick the menu items sequentially from 1 to 4. The only difference is that in the crashing version, a UserControl is added as a control to a Panel instead of directly to a Form... After closing the form created in step 4, the application freezes, sometimes terminates with an ObjectDisposedException ... Cheers, Gunther :omg: ------------- CODE STARTS HERE ------------- // define "CRASH" to have it crash when you go from 1 to 4 ... #define CRASH using System; namespace TestApp { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { [STAThread] static void Main() { System.Windows.Forms.Application.Run(new Form1()); } private System.Windows.Forms.Panel panel1; public Form1() { this.panel1 = new System.Windows.Forms.Panel(); this.SuspendLayout(); // // Menu // this.Menu = new System.Windows.Forms.MainMenu(); System.Windows.Forms.MenuItem mi = new System.Windows.Forms.MenuItem("Crashing!?"); this.Menu.MenuItems.Add(mi); mi = new System.Windows.Forms.MenuItem("1. Create Control"); mi.Click += new EventHandler(this.Create_Click); this.Menu.MenuItems[0].MenuItems.Add(mi); mi = new System.Windows.Forms.MenuItem("2. Display Dialog"); mi.Click += new EventHandler(this.Dialog_Click); this.Menu.MenuItems[0].MenuItems.Add(mi); mi = new System.Windows.Forms.MenuItem("3. Destroy Control"); mi.Click += new EventHandler(this.Destroy_Click); this.Menu.MenuItems[0].MenuItems.Add(mi); mi = new System.Windows.Forms.MenuItem("4. Display Dialog"); mi.Click += new EventHandler(this.Dialog_Click); this.Menu.MenuItems[0].MenuItems.Add(mi); mi = new System.Windows.Forms.MenuItem("-"); this.Menu.MenuItems[0].MenuItems.Add(mi); mi = new System.Windows.Forms.MenuItem("Quit"); mi.Click += new EventHandler(this.Quit_Click); this.Menu.MenuItems[0].MenuItems.Add(mi); // // panel1 // this.panel1.AutoScroll = true; this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; this.panel1.Location = new System.Drawing.Point(0, 0); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Siz

      J Offline
      J Offline
      je_gonzalez
      wrote on last edited by
      #2

      Reason, I cannot give, but fix I can: Replace: if (this.panel1.Controls[i].GetType() == typeof(System.Windows.Forms.UserControl)) this.Controls.RemoveAt(i); With: if (this.panel1.Controls[i].GetType() == typeof(System.Windows.Forms.UserControl)) { this.panel1.Controls[i].Controls.Clear(); this.panel1.Controls.RemoveAt(i); } Ran into this a while back....

      G 1 Reply Last reply
      0
      • J je_gonzalez

        Reason, I cannot give, but fix I can: Replace: if (this.panel1.Controls[i].GetType() == typeof(System.Windows.Forms.UserControl)) this.Controls.RemoveAt(i); With: if (this.panel1.Controls[i].GetType() == typeof(System.Windows.Forms.UserControl)) { this.panel1.Controls[i].Controls.Clear(); this.panel1.Controls.RemoveAt(i); } Ran into this a while back....

        G Offline
        G Offline
        GuntherR
        wrote on last edited by
        #3

        Thanks je, your suggestions works. However, meanwhile I also found that simply calling a Dispose() instead of the RemoveAt() also works. I also realized that my original problem was twofold - the one from the posted source, the other, giving the DisposeException only occurs when a LinkLabel control was part of a GroupBox on a UserControl ... Well, I just avoid having those in GroupBoxes for now ... Regards, Gunther

        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