API 2.0: Threads

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?

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

I don’t see the ()

From the documentation itself… it makes sense to me:

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

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

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:

[code]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


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[/code]

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

[code]thread.UIupdate (1)[/code]

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:

[code]UIdict.Value("action") = action
UIdict.Value("arg1")   = arg1
UIdict.Value("arg2")   = arg2


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

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