Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB .NET Problem With Threads

Status
Not open for further replies.

Zerxer

Programmer
Mar 20, 2008
3
US
Alright so I have a relatively small program that uses threading. It's an image uploading program so when it's ready to upload an image, it creates a new thread to upload the image through as to not lock up the rest of the program while it's sending all the data. Since it's a small program, I have set Control.CheckForIllegalCrossThreadCalls to False so that I can access objects on the main form from the other thread (so that I can let them know the current progress).

Now, I have my sock class with every variable in it and every function in it being labeled as Shared. When it's ready to upload something, it does the following:

sock.File = File
Dim t As New Thread(AddressOf sock.UploadIt)
t.Start()

I also don't create a variable in my form to reference my sock class; I just directly access the class.

Okay so my problem is this: in my UploadIt function, I have it do p.Show() while p is set in the global scope of the class as "Shared p As frmProgress = frmProgress" and my frmProgress is a small form with a progress bar on it. Once it's done uploading, the UploadIt function calls another function in the class called Parse() where it then does p.Hide(). It should be noted that the frmProgress isn't shown before I first call that p.Show(). It works fine during the first call but after I Hide it like that, it won't show again when it goes to upload another image. This also happened to me when I had the progress bar on my main form with the Visible property set to False as default; during the first run-through, it would Show my progress bar but would then not show it the next run-through. Another strange thing is that I don't even have to call p.Hide(), it will automatically re-hide it once the thread has exited and again I can't reshow it the next time (same was with the progress bar itself). When I try to access the .Visible property during anything but the first run, it says it cannot access it.

What exactly is the problem here? I hope I provided enough information to give a clear picture for all of this. If anyone has an answer for me, I will greatly appreciate it. Thanks!
 
Nevermind. I set it so each time the thread runs, it sets p as a new instance of frmProgress since frmProgress is only a little tiny semi-transparent form with a progress bar on it that gets closed after upload is finished. It works fine now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top