"Thread-Safe Calls" with "Invoke" method to Winform control leads very heavy memory leak!!

Posted by konnychen on Stack Overflow See other posts from Stack Overflow or by konnychen
Published on 2010-06-03T09:15:44Z Indexed on 2010/06/03 12:04 UTC
Read the original article Hit count: 276

Filed under:
|
|
|

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);
    }

© Stack Overflow or respective owner

Related posts about memory

Related posts about thread