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 / November 2006

Tip: Looking for answers? Try searching our database.

Control.Remove() increases CPU usage and hangs application

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kamlesh - 28 Nov 2006 19:54 GMT
Hey guys,

I have an app where i create a text box dynamically on a control and
user enters something and once looses focus (leave event) i remove it
from the user control.

Once i try to focus another control in the app, Control.Remove() hangs
the app and when i see the stacktrace Control. (app hangs in the
Control.GetNextControl() method.

here is code to create and remove textboxes.
am i missing something? Do i need to use GC.Collect()???

any help would be appreciated.

private void GenerateTextBox(Point location, Size size)
{
 if (textArea_ == null)
 {
      this.SuspendLayout();
      /Code for dynamically displaying the textbox for inline editing
      textArea_ = new TextBox();
      textArea_.Location = location;
      textArea_.Size = size;
      textArea_.Multiline = true;
      textArea_.MaxLength = 200;
      textArea_.BorderStyle = BorderStyle.FixedSingle;
      textArea_.Leave += new EventHandler(this.textArea_Leave);
      textArea_.Font = new System.Drawing.Font("Tahoma", 8.25F,
      System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
      textArea_.KeyDown += new KeyEventHandler(textArea_KeyDown);

      this.Controls.Add(textArea_);
      textArea_.Focus();
      textArea_.BringToFront();
      this.ResumeLayout();

}
}

//Method to remove the dynamic text box from the area
private void RemoveTextBox()
{
       if (textArea_ != null)
       {
               this.SuspendLayout();
               if (this.Controls.Contains(textArea_))
               {
                      textArea_.Leave -= new
EventHandler(textArea_Leave);
                      this.Controls.Remove(textArea_);
                      textArea_.Dispose();
                      textArea_ = null;
               }
               this.ResumeLayout();
       }
RobinS - 28 Nov 2006 21:34 GMT
I see this posted in multiple newsgroups. If you're
going to do this, please cross-post, i.e. post it in
all the different newsgroups at one time. That way,
if someone in one newsgroup provides a solution, it is
displayed in all of the groups, and people know it is
solved, and they don't need to spend time on it, and
they can help someone else.

At the very least, since you have multi-posted it,
when/if you *do* get a solution, go post it in the
other groups where you posted this message.

Thanks,
Robin S.
-------------------------------
> Hey guys,
>
[quoted text clipped - 53 lines]
>                this.ResumeLayout();
>        }
kamlesh - 29 Nov 2006 00:41 GMT
Hi Robin,

sorry for multi posting.
I wasnt aware of the options.

Will post the solution if i get it in the other news group.

Thanks,
Kamlesh.

> I see this posted in multiple newsgroups. If you're
> going to do this, please cross-post, i.e. post it in
[quoted text clipped - 68 lines]
> >                this.ResumeLayout();
> >        }

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.