1.) In whatever object you have that calls the updater code, create a Delegate with the same signature as the event you want to handle (just like add handler):
Private Sub delAsyncUpdateComplete(sender as UpdateCheckClass, result as Kaju.UpdateChecker.ResultType)
2.) Create a property in this object of that type of delegate:
Private Property AsyncUpdateCompleteCallBack as delAsyncUpdateComplete
3.) Create a Handler Method for your Delegate:
Private Sub HandleAsyncUpdateComplete(sender as UpdateCheckClass, result as Kaju.UpdateChecker.ResultType)
If AsyncUpdateCompleteCallBack <> Nil Then
4.) Create a Set Method to set the callback for the delegate:
Sub SetAsyncUpdateCompleteHandler(theCallback as delAsyncUpdateComplete)
mUpdateCheckInstance.AsyncUpdateCompleteCallBack = theCallback
5.) Set an initial AddHandler for the event in the constructor of your object:
AddHandler AsyncUpdateComplete, AddressOf HandleAsyncUpdateComplete
Be sure to set a remove handler in your close event for the object.
Now, wherever you want to use this update object, you can easily create a method, and set that method to be the event handler. No need to worry if AddHandler or RemoveHandler has been called. You can call do this anywhere you want:
So my object that does all the checking is called UpdateCheckClass and it's actually a Singleton so I can call it anywhere in the app and I don't have to worry about instantiating it (and in the case of a Singleton, the method in step 4 is actually a Shared Method.
My UpdateCheckComplete event has the following singature/code:
Public Sub UpdateCheckCompleteEvent(u as UpdateCheckClass, UpdateResult as Kaju.UpdateChecker.ResultType)
UpdateCheckClass.SetAsyncUpdateCompleteHandler(Nil) // HERE IS WHERE I REMOVE THE HANDLER
Select Case UpdateResult
MsgBox "There was an updater error."
MsgBox "There is an update available but you have chosen to ignore it."
MsgBox "No update is available at this time."+EndOfLine+EndOfLine+"You have the most current version."
MsgBox "There is an update already in progress."
So basically as soon as the event handler method is called, I then remove it.
I've got one more layer of an event in here from the socket that uses a traditional Add/Remove Handler directive, but I'm going to skip that. This should be enough to get you going. If not, I can try to throw my code into a project for you.
So this is specifically for the Kaju Updater object I am working with. Your case may be a different class, but the same principles still apply. The PageReceived event of the Xojo.Net.HTTPSocket is the offending event. So I would use what I do above for that event in your HTTPSocket. It's signature is:
Event PageReceived(url As String, httpStatus As Integer, content As String)
So create the Delegate and necessary handler methods and callbacks with this signature and then you can add/remove the event at will in code. It's pretty cool.