"Thread-Safe Calls" with "Invoke" method to Winform control leads very heavy memory leak!!
- by konnychen
In the following link: "Make Thread-Safe Calls to Windows Forms Controls http://msdn.microsoft.com/en-us/library/ms171728.aspx"
We can see an example which provide cross tread access to a winform control.
But if the thread is in a while loop, it will cause the heavy memory leak. As I use taskmanage I can see the memory is increasing. Can anyone help me to solve the problem?
oThread2 = new Thread(new ThreadStart(Cyclic_Call));
oThread2.Start();
delegate void SetText_lab_Statubar(string text);
private void m_SetText_lab_Statubar(string text)
{
if (this.lab_Statubar.InvokeRequired)
{
SetText_lab_Statubar d = new SetText_lab_Statubar(m_SetText_lab_Statubar);
this.Invoke(d, new object[] { text });
}
else
{
this.lab_Statubar.Text = text;
}
}
private void Cyclic_Call()
{
do
{
this.m_SetText_lab_Statubar("This string is set from thread"); Thread.Sleep(100);
}
while (!b_AbortThraed);
}