API 2.0: Threads

  1. last week

    Martin T

    Nov 30 Pre-Release Testers Germany

    I am currently working on the new thread method AddUserInterfaceUpdate and the new thread event UserInterfaceUpdate . This method has as parameter data() As Dictionary. I wonder why it is a dictionary array. My understanding of the AddUserInterfaceUpdate method tells me that by inserting pairs (e.g. AddUserInterfaceUpdate(1 : 1)) I only need a single dictionary in the UserInterfaceUpdate event. Why is a dictionary array passed as a parameter there?

  2. Rick A

    Nov 30 Pre-Release Testers (Brazil. UTC-3:00)

    Weird, data() As Pair makes much more sense. Doc flaws?

  3. Dave S

    Nov 30 San Diego, California USA

    Thread.AddUserInterfaceUpdate(data as Dictionary)

    I don't see the ()

  4. Javier M

    Nov 30 Pre-Release Testers, Xojo Pro, Third Party Store AprendeXojo - Europe, Spain

    From the documentation itself… it makes sense to me:

    "Each call to AddUserInterfaceUpdate in the Run event, adds the values passed to an array that is then passed to the UserInterfaceUpdate event (the data() parameter above). This allows you to process all of the calls to AddUserInterfaceUpdate or just the most recent one. For example, if your thread was reading a series of files and you wished to add the name of each file read to a ListBox, you'd want to read each row of the data() array passed to this event. However, if you instead were only displaying a ProgressBar and wanted to show how far you'd gotten through reading all the files, it would be more efficient to read the last item of the data() array passed to this event and then update your ProgressBar control rather than iterate through all of the items in the data() array."

    So, for that you need to receive an Array of Dictionaries and not just one Dictionary.

  5. Derk J

    Nov 30 Pre-Release Testers, Xojo Pro

    @Rick A Weird, data() As Pair makes much more sense. Doc flaws?

    A paramarray doesn't require a multiple of Pairs.
    You can just give it a single Pair

  6. Tim S

    Nov 30 Pre-Release Testers Canterbury, UK

    @MartinTrippensee I am currently working on the new thread method AddUserInterfaceUpdate and the new thread event UserInterfaceUpdate . This method has as parameter data() As Dictionary. I wonder why it is a dictionary array.

    I do this:

    When I instantiate the thread, I do:

    AddHandler myThread.UserInterfaceUpdate,  WeakAddressOf updateUI      // Wire in the UI updater function for this thread

    and to carry out the UI updates I have:

    Sub updateUI (t As taskClass, UIdata() As Dictionary)
    
    Var  updateItem as new Dictionary, message As UIupdateItem
    
    while  (UIdata.LastRowIndex>-1)
      
    updateItem = UIdata(0)
    message    = updateItem.Value(0)
    UIdata.RemoveRowAt (0)
    
    select case message.action
      
    case 1                                                                     // Update the dock icon
      updateIcon ()
      
    case 2
    ...
    
    end select
    
    wend
    
    End Sub

    To create a new update action my thread class (taskClass) has this method:

    sub UIupdate (action As integer, optional arg1 As variant, optional arg2 As Variant, optional arg3 As Variant, optional arg4 As Variant)
    
    // Stores the requested UI update and sends it off for actioning.
    
    Var  message As new UIupdateItem, UIdict As new Dictionary
    
    message.action = action
    message.arg1   = arg1
    message.arg2   = arg2
    message.arg3   = arg3
    message.arg4   = arg4
    
    UIdict.Value(0) = message
    
    me.AddUserInterfaceUpdate (UIdict)
    
    end sub

    So if my thread decides that the Dock icon needs updating, it can just do:

    thread.UIupdate (1)

    and by using an array of dictionaries, it can make many such calls which just pile up and are then handled one by one by the event handler.

    Alternatively I suppose I could have put the various parameters in directly as keys to the dictionary, such as:

    UIdict.Value("action") = action
    UIdict.Value("arg1")   = arg1
    UIdict.Value("arg2")   = arg2

    etc

  7. Rick A

    Nov 30 Pre-Release Testers (Brazil. UTC-3:00)

    @Derk J A paramarray doesn't require a multiple of Pairs.

    The "Weird, data() As Pair makes much more sense" comment was for this part not involving ParamArrays but Arrays:

    @MartinTrippensee This method has as parameter data() As Dictionary

  8. Tim J

    Dec 1 Pre-Release Testers N. Phoenix, AZ

    BTW - for those of us using the Task module in pre-API 2, this is the same thing.

or Sign Up to reply!