PC Review


Reply
Thread Tools Rate Thread

Control.Remove() increases CPU usage and hangs application

 
 
kamlesh
Guest
Posts: n/a
 
      28th Nov 2006
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();
}

 
Reply With Quote
 
 
 
 
RobinS
Guest
Posts: n/a
 
      28th Nov 2006
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.
-------------------------------
"kamlesh" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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();
> }
>



 
Reply With Quote
 
kamlesh
Guest
Posts: n/a
 
      29th Nov 2006
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.


RobinS wrote:
> 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.
> -------------------------------
> "kamlesh" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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();
> > }
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CPU usage and HDD activity increases after boot up - XP kimiraikkonen Windows XP Help 5 24th Feb 2007 01:29 PM
Excel memory usage increases without stopping svenkkk Microsoft Excel Discussion 0 15th Dec 2005 09:49 AM
Memory usage increases with ADO.NET v2.0 RTM Stuart Carnie Microsoft ADO .NET 8 4th Nov 2005 06:26 PM
CPU Usage Increases when printing A P Windows XP General 4 27th Jan 2005 11:20 AM
Shift Key Increases csrss.exe CPU Usage =?Utf-8?B?QmlsbA==?= Windows XP Help 4 20th Dec 2004 06:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:50 AM.