Hi! I know this is riddiculous, but i cant change text on my labels. Im using VS 2010 .NET C++, and simply using label1->Text = L"abcd"; gives me nothing. How do i change text under that label in that freakin language?
Anyone? I've just discovered, that if i put a button on my form, and onclick() i put this->label1->Text = L"abcd"; it accually works. But i want it to work within my backgroundworker. Is that possible?
Do you really think it's appropriate to bump after as little as 39 minutes!?
I've just discovered, that if i put a button on my form, and onclick() i put this->label1->Text = L"abcd"; it accually works. But i want it to work within my backgroundworker. Is that possible?
Well, that perfectly explains why this seemingly simple operation failed. The simple and fundamental rule is: Never do GUI manipulations directly from a worker thread! The way out of this dilemma is to either call the label's property set accessor in a thread-safe way (http://msdn.microsoft.com/en-us/library/ms171728.aspx is probably a good place to start reading about that) or to have the BackgroundWorker class do the inter-thread communication for you the right way by "abusing" BackgroundWorker's progress reporting feature to some extent.
An example of doing the latter can be found in http://www.codeguru.com/forum/showthread.php?p=2012459. Note that the way I did it there actually is more convoluted than it basically needs to be due to accomodating to the given scenario. Also note that the code in that thread is no example how to write code the right way, rather of getting the best out of the situation once the damage is done...
And if your intention behind changing the label's text even is to report some sort of progress, this isn't even an abuse. Actually, what I do in the code posted in the thread I linked to above is some sort of progress report as well, it's just not reported in terms of "percent completed" which is strongly suggested by the design of the BackgroundWorker's progress reporting interface.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.