Theading success (and a little gotcha lurking...)

Visual Studio192
I am so happy about this I had to tell someone and since no one at the

house even knows how to spell VB, I just had to make a short post.



I finally got my little program to correctly do a second thread for the

daily FTP upload. Not doing so was locking up the UI and causing it to

go white-screen. It is also not taking more than 60 seconds and the

timer was popping (yes, I know it is stoppable).



AND, I had to update a status (label) box and that took putting in the

second bit of code and there was a gotcha in there but I got it working,

finally. The update code was a little more complex than just blasting

the text in the box. It queues up messages if one was already showing

and put in a notice to click for more messages. Too cute!



Here's the gotcha in the thread-side UI update of the label text.



I had several forms and a module (quite standard). I put the code in

the module to accept the text destined for the label and called it with

the proper use of a delegate. It did not work. Why? Don't know but

the connection did not work when using the following (not sure which one

failed but I think it was the first line):



formname.lblStatus.InvokeRequired

Dim newDelegate As New UIDelegate(AddressOf StatusAdd)

formname.lblStatus.Invoke(newDelegate)



The following works in the label-owning form:



If lblStatus.InvokeRequired Then

Dim newDelegate As New UIDelegate(AddressOf StatusAdd)

lblStatus.Invoke(newDelegate)

Else



Since the routine was called from more than one form, it was natural to

have it in the module but it just did not work there. It seems the

routine and test has to be in the form which owns the label. So I moved

the routine to the owning module and prefaced the calls to it from the

other form(s) with the form name. Don't ask me! I know it cost some

time because I did not know where the problem really was.



HOORAY!!!



Silly note. I had the "chance" to go back to the VB6 IDE the other day.

I am amazed at how FAST I have gotten used to using the new IDE and how

clunky the VB6 one feels now. With all its problems, it is still

better. Now, if FIND would just FIND inside visually collapsed code...

Why the designers thought that you would not want to find stuff because

you were saving screen space is a continuing mystery!



Mike


-