Can I do this (threading and UI control update)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Just_a_fan@home.net

    Can I do this (threading and UI control update)

    I want to be able to call my thread safe routine in a more normal way
    but I cannot figure out the syntax or even if there is any. I have
    tried all variations I can think of.

    What I would like to code is:

    StatusAdd("Here is the text to display.")

    But what I do now is:

    Sub Thread2StatusTe st()
    StatusBoxConten ts = "Here is the text to display."
    StatusAdd()
    End Sub

    The routine it calls is below. It sees if a delegate invoke is needed
    and recalls itself on the control in the main thread. It works just
    fine but I would like to be able to call with one statement with a
    parameter of what to display rather than the clunky dual statements.

    It is the invoke call where the parameter gets lost and I don't know how
    to pass it otherwise.

    If I put an input parm spec on StatusAdd such as:

    Public StatusAdd(sIn as string)

    Then I have to put in:

    Delegate Sub UIDelegate(ByVa l sIn As String)

    And then I have a problem with a message saying that the expression does
    not produce a value on the following:

    lblStatus.Invok e(newDelegate(s In))

    Suggestions?

    Mike

    ---------------------The routine with the delegate invoke---------------

    Public Sub StatusAdd()

    'This routine HAS to be in the form which owns the control which
    will be shared with other threads for reading and writing.
    'It CANNOT be in the module file (for some reason I am not sure of
    at this time).

    Dim lArrayEntries As Integer

    If lblStatus.Invok eRequired Then ' If I am on a thread other than
    the one which owns the lblStatus control...

    'Update the status box by invoking a delegate with the UI control
    Dim newDelegate As New UIDelegate(Addr essOf StatusAdd) ' Queue up
    some work for lblStatus to run StatusAdd
    '--or-- Dim newDelegate As UIDelegate = AddressOf StatusAdd

    lblStatus.Invok e(newDelegate)
    Else

    If Strings.Len(Str ings.Trim(Statu sBoxContents)) = 0 Then Exit Sub
    ' Don't queue up an empty string.

    If lblStatus.Text = "" Then ' First, see if there is any text
    in the box.
    lblStatus.Text = "(" & Now() & ") " & StatusBoxConten ts ' If
    not, just put this text up for viewing and exit
    Exit Sub
    Else
    lStatusQueue += 1
    If Not (lblStatus.Text .EndsWith("(cli ck for more)")) Then
    lblStatus.Text &= " (click for more)"
    End If
    If sStatusQueue Is Nothing Then
    lArrayEntries = 0
    Else
    lArrayEntries = UBound(sStatusQ ueue)
    End If
    If lStatusQueue >= lArrayEntries Then ReDim Preserve
    sStatusQueue(lS tatusQueue)
    sStatusQueue(lS tatusQueue) = "(" & Now() & ") " &
    StatusBoxConten ts
    End If
    End If
    End Sub

  • Armin Zingler

    #2
    Re: Can I do this (threading and UI control update)

    "Armin Zingler" <az.nospam@free net.deschrieb
    and it works!
    I mean it can be compiled. If I undestood you correctly, you have a
    compile problem, not a runtime exception.


    Armin

    Comment

    Working...