Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / October 2004

Tip: Looking for answers? Try searching our database.

Bug report: Dispose for UserControl causes infinite loop

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ken Jiang - 26 Oct 2004 14:53 GMT
Say we have a Form F, containing a UserControl Uc, which does some
action on a WindowsTimer callback. If F also contains a timer and this
timer has an interval shorter than its callback latency, then
Uc.Dispose() will cause an infinite loop.

The attached sample ilustrates the problem. Pressing a button
toggles between creating/destroying a UserControl. This works fine as
long as the form's timer callback is kept under <100 ms (the form's
timer interval). The attached sample uses 200ms and locks up after
pressing the create/destroy button a couple of times.

Any suggestions for workarounds? TIA.

-------------------------------------------------------

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace WindowsApplication4
{
  public class UserControl1 : System.Windows.Forms.UserControl
  {
     private System.Windows.Forms.Timer timer1;
     private System.ComponentModel.IContainer components;
     
     public UserControl1()
     {
        this.components = new System.ComponentModel.Container();
        this.timer1 = new System.Windows.Forms.Timer(this.components);

        this.timer1.Enabled = true;
        this.timer1.Tick += new System.EventHandler(this.timer1_Tick);

        this.BackColor = System.Drawing.Color.RosyBrown;
        this.Name = "UserControl1";
        this.Size = new System.Drawing.Size(104, 24);
     }

     protected override void Dispose( bool disposing )
     {
        if( disposing )
        {
           if(components != null)
           {
              components.Dispose();
           }
        }
        base.Dispose( disposing );
     }

     private void timer1_Tick(object sender, System.EventArgs e)
     {}
  }

  public class Form2 : System.Windows.Forms.Form
  {
     private System.Windows.Forms.Timer timer1;
     private System.Windows.Forms.Button button1;
     private System.ComponentModel.IContainer components;

     [STAThread]
     public static void Main()
     {
        Application.Run(new Form2());
     }

     public Form2()
     {
        InitializeComponent();
     }

     private void InitializeComponent()
     {
        this.components = new System.ComponentModel.Container();
        this.timer1 = new System.Windows.Forms.Timer(this.components);
        this.button1 = new System.Windows.Forms.Button();
        this.SuspendLayout();

        this.timer1.Enabled = true;
        this.timer1.Tick += new System.EventHandler(this.timer1_Tick);

        this.button1.Location = new System.Drawing.Point(112, 192);
        this.button1.Text = "Ok";
        this.button1.Click += new System.EventHandler(this.button1_Click);

        this.Controls.Add(this.button1);
        this.ResumeLayout(false);

     }

     UserControl1 myUserControl;
   
     private void button1_Click(object sender, System.EventArgs e)
     {
        if (myUserControl == null)
        {
           myUserControl = new UserControl1();
           myUserControl.Parent = this;
        }
        else
        {
           myUserControl.Dispose();
           myUserControl = null;
        }
     }

     private void timer1_Tick(object sender, System.EventArgs e)
     {
        System.Threading.Thread.Sleep(200);
     }
  }
}

Signature

Heehee

"Jeffrey Tan[MSFT]" - 27 Oct 2004 08:46 GMT
Hi Ken,

I have reproduced our your issue, I will spend some time on this issue. I
will update you ASAP. Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

"Jeffrey Tan[MSFT]" - 28 Oct 2004 04:22 GMT
Hi Heehee,

Sorry for letting you wait for so long.

After doing some research, I found there is nothing wrong with your
application, so I think this maybe a bug of our product(just as you said in
title). So I have contacted our product team for this issue.

Now, I received a feedback from our product team to confirm this issue as a
bug, it has be added into product's internal database.

Thanks very much for your product feedback and sharing information with the
community!! Your feedback will make our product get better and better.
============================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

"Jeffrey Tan[MSFT]" - 29 Oct 2004 04:23 GMT
Hi Heehee,

Yes, because this issue is a bug of our product, you may obtain a hotfix
for this issue for free. You may create a free incident from Microsoft PSS,
please refer to:
http://www.microsoft.com/services/microsoftservices/supp.mspx?gssnb=1

Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.