p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   BOOK: Professional VB.NET, 2nd Edition or 2003 (http://p2p.wrox.com/book-professional-vb-net-2nd-edition-2003-50/)
-   -   Chapter 19 - Pooling Sample Code (http://p2p.wrox.com/book-professional-vb-net-2nd-edition-2003/77189-chapter-19-pooling-sample-code.html)

dmn November 27th, 2009 07:39 AM

Chapter 19 - Pooling Sample Code
Has anyone managed to get the Pooling sample to work? I have created my own application and downloaded the sample code for the book and both fail to run with the same problem.


System.InvalidOperationException was unhandled

"Cross-thread operation not valid: Control 'txtStatus' accessed from a thread other than the thread it was created on."
The VS online help seems to be suggesting that we need to invoke the update to the control.

I've coded around the problem by sending the data to the output window.

To prove that I could get data back to the form I modified the WorkerEnd method to pass back some additional data that is stored in private member variables. I then have a timer that loops around and updates the UI every few seconds.

BillS November 27th, 2009 09:23 PM

Old Version
I believe the issue is with the age of the book. In .NET 1.1 and before you could directly access the UI elements on the main thread from a worker thread. However, in .NET 2.0 (I believe) this changed so that you could no longer directly access UI elements from a worker thread. The samples written to do so will not work on current versions of .NET. Take a look at threading from a new version of the book (the code sample) and I expect you'll find that it no longer directly accesses the UI elements from a worker thread.

All times are GMT -4. The time now is 03:37 PM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
2013 John Wiley & Sons, Inc.