T
Teremock
Hi
I have a resource leak in the very simple project.
Project contains Form with one TextBox control in multiline mode.
After start this app I open Task Manager and see "Handles" count incremental
on every 1 second.
The source code is following:
public partial class Form1 : Form
{
System.Threading.Timer tm;
public Form1()
{
InitializeComponent();
// start timer 1 second interval ...
tm = new System.Threading.Timer(OnTimer, null, 0, 1000);
}
void OnTimer(Object state)
{
// add text in thread safe mode ...
AddTerminalText(" Resource Leak!!! ");
}
delegate void AddTextCallback(string text);
AddTextCallback d;
object[] arg = new object[1];
private void AddTerminalText(string text)
{
if (textBox1.InvokeRequired)
{
if (d == null)
{
d = new AddTextCallback(AddTerminalText);
}
arg[0] = text;
textBox1.Invoke(d, arg);
}
else
{
textBox1.AppendText(text); // add text into control
....
}
}
}
I don't understand what's wrong
Please help anybody !!!
Roman
I have a resource leak in the very simple project.
Project contains Form with one TextBox control in multiline mode.
After start this app I open Task Manager and see "Handles" count incremental
on every 1 second.
The source code is following:
public partial class Form1 : Form
{
System.Threading.Timer tm;
public Form1()
{
InitializeComponent();
// start timer 1 second interval ...
tm = new System.Threading.Timer(OnTimer, null, 0, 1000);
}
void OnTimer(Object state)
{
// add text in thread safe mode ...
AddTerminalText(" Resource Leak!!! ");
}
delegate void AddTextCallback(string text);
AddTextCallback d;
object[] arg = new object[1];
private void AddTerminalText(string text)
{
if (textBox1.InvokeRequired)
{
if (d == null)
{
d = new AddTextCallback(AddTerminalText);
}
arg[0] = text;
textBox1.Invoke(d, arg);
}
else
{
textBox1.AppendText(text); // add text into control
....
}
}
}
I don't understand what's wrong
Please help anybody !!!
Roman