How to check if offline or online (quickly)
Posted: Fri May 28, 2021 10:53 am
I'm building an app with offline capability and I need a way to check quickly if I'm offline or not .
I'm currently using #SYS_WEB.online but it seem unreliable so I do a call to the server module and if it failed that means I'm offline.
It is working but it takes about 20 seconds so I want a better way of handling it.
Here's the code that I'm working on:
Evtroutine Handling(#SaveIcon.Click)
If (#COM_OWNER.Validate( Update #xContacts ))
* this don't appear to be working
If (#SYS_WEB.online *EQ True)
#COM_OWNER.Save
Else
#COM_OWNER.SaveOffline
Endif
Endif
Endroutine
Mthroutine Name(Save) Access(*PRIVATE)
Define_Com Class(#EX_DataServer.Save) Name(#Save)
#SYS_MSGQ.ClearAll
#ErrorText.Visible := False
#Save.ExecuteAsync( #Fields #STD_BLOB #STD_CODE )
Evtroutine Handling(#Save.Completed)
If (#STD_CODE = "OK")
#COM_OWNER.Close
Signal Event(ItemSaved) Action(#DF_EFLAG) Id(#xContactIdentification)
Else
#ErrorText.Caption := ""
For Each(#Message) In(#SYS_MSGQ.Messages)
#ErrorText.Caption += #Message.Text + (10).AsUnicodeString
Endfor
#ErrorText.Visible := True
#Details.VerticalScrollPos := 0
* #COM_OWNER.Close
Endif
Endroutine
Evtroutine Handling(#Save.Failed) Handled(#handled)
#COM_OWNER.SaveOffline
#handled := true
#COM_OWNER.Close
Endroutine
Endroutine
Thanks,
Eduardo
I'm currently using #SYS_WEB.online but it seem unreliable so I do a call to the server module and if it failed that means I'm offline.
It is working but it takes about 20 seconds so I want a better way of handling it.
Here's the code that I'm working on:
Evtroutine Handling(#SaveIcon.Click)
If (#COM_OWNER.Validate( Update #xContacts ))
* this don't appear to be working
If (#SYS_WEB.online *EQ True)
#COM_OWNER.Save
Else
#COM_OWNER.SaveOffline
Endif
Endif
Endroutine
Mthroutine Name(Save) Access(*PRIVATE)
Define_Com Class(#EX_DataServer.Save) Name(#Save)
#SYS_MSGQ.ClearAll
#ErrorText.Visible := False
#Save.ExecuteAsync( #Fields #STD_BLOB #STD_CODE )
Evtroutine Handling(#Save.Completed)
If (#STD_CODE = "OK")
#COM_OWNER.Close
Signal Event(ItemSaved) Action(#DF_EFLAG) Id(#xContactIdentification)
Else
#ErrorText.Caption := ""
For Each(#Message) In(#SYS_MSGQ.Messages)
#ErrorText.Caption += #Message.Text + (10).AsUnicodeString
Endfor
#ErrorText.Visible := True
#Details.VerticalScrollPos := 0
* #COM_OWNER.Close
Endif
Endroutine
Evtroutine Handling(#Save.Failed) Handled(#handled)
#COM_OWNER.SaveOffline
#handled := true
#COM_OWNER.Close
Endroutine
Endroutine
Thanks,
Eduardo