Hey guys,

I've got a multithreaded application done in C# but the label on one of my forms won't update! It doesn't do anything

public IndividualPCSpec(AllKnownDevicesFrm parent)
        {
            m_Parent = parent;
            InitializeComponent();
            m_IPAddressLbl.Text = "HELLO";
        }

        public void showInformation(ComputerHardware dto) 
        {
            
            m_IPAddressLbl.Text = "HELLO WORLD";
            this.Refresh();
            this.m_IPAddressLbl.Refresh();

            Application.DoEvents();
        }

I don't get why.... it doesn't even get set to "Hello" :S

How are you calling this functions?

from another class.

Class X
IndividualPCSpec m_individualPC = new IndividualPCSpec (this);
ComputerHardware  dto = new ComputerHardware(...);
..
..
Function X() 
{
showInformation(dto);
}
}

If you attach a debugger, does it show the line m_IPAddressLbl.Text = "HELLO WORLD"; running?

Normally updating labels in a form is not a thread-safe operation. Check this article out:

http://msdn.microsoft.com/en-us/library/ms171728(VS.80).aspx

That may give you a good idea of what you have to do to update the label. You need to invoke another method to update the label's text. I'm surprised an exception is not being thrown...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.