Re: Control.Remove() increases CPU usage and hangs application

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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" <kamleshgk@xxxxxxxxx> wrote in message
news:1164743658.723281.232670@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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();
}


.



Relevant Pages

  • Re: Control.Remove() increases CPU usage and hangs application
    ... I see this posted in multiple newsgroups. ... from the user control. ... Once i try to focus another control in the app, ... textArea_ = new TextBox; ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Control.Remove() increases CPU usage and hangs application
    ... I see this posted in multiple newsgroups. ... from the user control. ... Once i try to focus another control in the app, ... textArea_ = new TextBox; ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Control.Remove() increases CPU usage and hangs application
    ... user enters something and once looses focus i remove it ... from the user control. ... Once i try to focus another control in the app, ... textArea_ = new TextBox; ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Control.Remove() increases CPU usage and hangs application
    ... user enters something and once looses focus i remove it ... from the user control. ... Once i try to focus another control in the app, ... textArea_ = new TextBox; ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: Opinion wanted
    ... the details including the nature of my own app (which you mischaraterized ... correct the current control (provided that control is invalid but invalid ... causes you to validate controls that have already been ... largely discreditted for good reason and has very little use these days. ...
    (microsoft.public.dotnet.framework.windowsforms)