Best practice to check if connected to the internet. Desktop app and web service

What I use on Windows

Public Function IsInternetConnected() As Boolean
  #If TargetWindows Then
    Declare Function InternetGetConnectedState Lib "wininet" (ByRef lpdwFlags As UInt32, dwReserved As UInt32) As Boolean
    
    Var flags As UInt32
    Return InternetGetConnectedState(flags, 0)
    
  #Endif
End Function