I have been looking everywhere for a clear example on how to upload a file with a Progress Bar. After some blog scraping, I managed to put together a simple class which demonstrates how to do this.
The code compiles, but I haven’t tested it, but it is my guesstimate that it’ll work right out of the box.
I’m not sure what your intention is with the CriticalSection, but two things, first the line in run which attempts to take a lock, ScopedLock Lock(CriticalSection);
is creating a local CriticalSection object and taking a lock on that, not on your member variable CriticalSection critical_section
Second, you don’t use the CriticalSection anywhere else in the code, so as I said, I am not sure what your intention is in using it.
Jacques, your thread safety here comes from setting the member variables during construction and then only accessing them from the background thread. So I think you are almost fine without that lock, except for “response_str” which will need a lock if you ever want to read it while the thread is running.
Maybe make it private member so you can’t access it any other way then two member functions that must always be used when accessing the string:
You might be right, but I think for the sake for 5 extra lines of code that’ll prevent you ever shooting yourself in the foot it’ll be worth adding the CriticalSection
You dont’ know what changes you’ll make in the future …