469,963 Members | 1,188 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,963 developers. It's quick & easy.

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

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

Jun 27 '08 #1
0 887

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.