Kaju self-updater talk (v.2.x)

  1. ‹ Older
  2. 2 weeks ago

    Jon O

    Apr 8 Pre-Release Testers, Xojo Pro Chicago Area USA

    Thanks, Tim. I've figured out how to "stop" the behavior from crashing my app, and I found a couple of spots where I don't think I was coding some things properly. When I was operating synchronously, I created my Kaju.Updater object locally in a method. Then I waited for and returned the result. When I moved to an Async connection, I added handlers to handle the async events, but I messed up by still using just a locally scoped Kaju.Updater object. So the object technically goes out of scope when the method completes, but it's held in memory because of the events still existing. I'm not sure if this was feeding the problem, but it certainly isn't good coding form!

    So I'm still going through and trying to figure if there's something I'm doing or the Xojo.Net.HTTPSocket is doing. Ideally, I'd like to update things to URLConnections and I know Kem wants to do that too, but right now, I don't know if I have time to do it myself.

  3. Kem T

    Apr 8 Pre-Release Testers, Xojo Pro, XDC Speakers New York

    There are known bugs in HTTP socket in 2018r4 on Windows, so that might be what you're seeing.

  4. Jon O

    Apr 8 Pre-Release Testers, Xojo Pro Chicago Area USA

    @Kem T There are known bugs in HTTP socket in 2018r4 on Windows, so that might be what you're seeing.

    OK. I have a feeling it might be. While my "out of scope" object was not good coding form, there's nothing with anything that I am doing (that I can see) that would cause the PageReceived event to fire non-stop.

  5. Aurelian N

    Apr 8 Pre-Release Testers, Xojo Pro

    @Jon O OK. I have a feeling it might be. While my "out of scope" object was not good coding form, there's nothing with anything that I am doing (that I can see) that would cause the PageReceived event to fire non-stop.

    Indeed I have same issue, I'm using the Xojo.net.HTTPSocket for a simple app that controls a device to open a door and I do have another socket that checks the status of it , like a heartbeat but the problem is that some times the socket goes nuts and it kills the app after max 30 min, on Mac so far it is stable .

  6. Jon O

    Apr 8 Pre-Release Testers, Xojo Pro Chicago Area USA

    @Aurelian N Indeed I have same issue, I'm using the Xojo.net.HTTPSocket for a simple app that controls a device to open a door and I do have another socket that checks the status of it , like a heartbeat but the problem is that some times the socket goes nuts and it kills the app after max 30 min, on Mac so far it is stable .

    OK. Well, what I have ended up doing is make sure that I remove the event handler for the socket as soon as I am done with it. This is most easily done setting up delegate methods and having a set method that you can just use to set the delegate to NIL. AddHandler and RemoveHandler work fine as well, but you have to be a little more specific with how you use them and wrap them in try/catch blocks so that you don't throw an exception if you've already removed the handler, etc.

    I've tested removing the event handlers and then adding them right back in to see if the socket is still going crazy. It isn't. Seems like as soon as the event handler is removed, the socket starts behaving itself.

  7. Aurelian N

    Apr 8 Pre-Release Testers, Xojo Pro

    @Jon O OK. Well, what I have ended up doing is make sure that I remove the event handler for the socket as soon as I am done with it. This is most easily done setting up delegate methods and having a set method that you can just use to set the delegate to NIL. AddHandler and RemoveHandler work fine as well, but you have to be a little more specific with how you use them and wrap them in try/catch blocks so that you don't throw an exception if you've already removed the handler, etc.

    I've tested removing the event handlers and then adding them right back in to see if the socket is still going crazy. It isn't. Seems like as soon as the event handler is removed, the socket starts behaving itself.

    Hi Jon,

    Can you please provide an example for that ?

    I will see tomorrow the project and maybe put it somewhere , so far works nice on Mac but windows it's a nightmare .

    Thanks .

  8. Jon O

    Apr 8 Pre-Release Testers, Xojo Pro Chicago Area USA
    Edited 2 weeks ago

    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
        AsyncUpdateCompleteCallBack.Invoke(Self,result)
      End If
    End Sub

    4.) Create a Set Method to set the callback for the delegate:

    Sub SetAsyncUpdateCompleteHandler(theCallback as delAsyncUpdateComplete)
      mUpdateCheckInstance.AsyncUpdateCompleteCallBack = theCallback
    End Sub

    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:

    UpdateCheckClass.SetAsyncUpdateCompleteHandler(AddressOf UpdateCheckCompleteEvent)

    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  
      Case Kaju.UpdateChecker.ResultType.Error
        MsgBox "There was an updater error."
      Case Kaju.UpdateChecker.ResultType.IgnoredUpdateAvailable
        MsgBox "There is an update available but you have chosen to ignore it."
      Case Kaju.UpdateChecker.ResultType.NoUpdateAvailable
        MsgBox "No update is available at this time."+EndOfLine+EndOfLine+"You have the most current version."
      Case Kaju.UpdateChecker.ResultType.UpdateAlreadyInProgress
        MsgBox "There is an update already in progress."
      End Select
    End Sub

    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.

  9. last week

    Tim P

    Apr 10 Pre-Release Testers Austin, TX

    This looks like the problem I saw, so it doesn't look like it's a Kaju problem :)
    https://forum.xojo.com/53353-net-httpsocket-pagereceived-problem

  10. Jon O

    Apr 10 Pre-Release Testers, Xojo Pro Chicago Area USA

    Yeah, I don't think it's a Kaju thing. I posted wondering if others had seen the same or if my implementation was causing an issue. Looks like others have seen the same thing. Dale is definitely correct.

or Sign Up to reply!