OK - thanks. I guess I’m too used to considering threads’ events not as events.
This is a known concept, i was expecting something like; directly assign the event to a handler (method) with the correct signature?
The above code allow us doing exactly that as:
Var download As New DelegatableURLConnection
download.ErrorEvent = AddressOf MyDownloadErrorHandler // assign the event to the handler
Then somewhere you write the method with the correct signature as
Public Sub MyDownloadErrorHandler(sender As Object, e As RuntimeException)
// Handle the download errors here
End Sub
Same for FileReceivedEvent and a method as
URLFileReceivedHandler(sender As Object, url As String, httpStatus As Integer, file As FolderItem)
If you prefer, instead of Object, you can declare sender directly as DelegatableURLConnection
I have subclassed Thread to add some properties and that is my standard thread class. Doing an audit I find I have 13 types of thread so I’m going to try sub-classing my own subclass, then I can assign the appropriate code directly in the event handlers concerned. No need for AddHandler or delegates at all. At lest that’s the idea but I’ve not tried it yet.
If you have a fixed code, ok. The above code allows to assign/change different handlers at runtime as AddHandler does, but without it, and not needing RemoveHandler as any new assignment replaces it.
For each type of thread I’ll have a new class. I think that’s probably marginally easier to manage as each one will have fixed code.
I have found this topic to be very useful so thanks to all who have contributed.