-
Notifications
You must be signed in to change notification settings - Fork 3
Verify an internet connection
Do not forget to add tis line of code on top of your code file:
C#
using LeoCorpLibrary;
VB
Imports LeoCorpLibrary
There is two methods to check if an internet connection is available or not:
- IsAvailable()
- IsAvailableTestSite()
They are in:
LeoCorpLibrary.NetworkConnection.IsAvailable()
This method is avaialable in version 1.1 and higher.
Compatibility
Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
---|---|---|
.NET 5 | ✔ | ✔ |
.NET Core 3.1 | ✔ | ✔ |
.NET Framework 4.7.2 | ✔ | ✔ |
.NET Framework 4.5 | ❌ | ✔ |
This method is trying to connection https://bing.com. If it manage to connect, it means that a connection to internet is available.
Here's an example of usage:
C#
if (NetworkConnection.IsAvailable()) { // If true
Console.WriteLine("Connected");
}else{
Console.WriteLine("Not connected");
}
VB
If (NetworkConnection.IsAvailable()) Then ' If true
Console.WriteLine("Connected")
Else
Console.WriteLine("Not connected")
End If
This method is avaialable in version 1.1 and higher.
Compatibility
Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
---|---|---|
.NET 5 | ✔ | ✔ |
.NET Core 3.1 | ✔ | ✔ |
.NET Framework 4.7.2 | ✔ | ✔ |
.NET Framework 4.5 | ❌ | ✔ |
This method is gonna try to connect to a specific page tha tyou specified. If it manages to connect to the website, it means there is an Internet connection.
You must specify a website like this:
Example:
IsAvailableTestSite("https://example.com")
Here's an example of usage:
C#
if (NetworkConnection.IsAvailableTestSite("https://example.com")) { // If true
Console.WriteLine("Connected");
}else{
Console.WriteLine("Not connected");
}
VB
If (NetworkConnection.IsAvailableTestSite("https://example.com")) Then ' If true
Console.WriteLine("Connected")
Else
Console.WriteLine("Not connected")
End If
This method is avaialable in version 2.1 and higher.
Compatibility
Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
---|---|---|
.NET 5 | ✔ | ✔ |
.NET Core 3.1 | ✔ | ✔ |
.NET Framework 4.7.2 | ✔ | ✔ |
.NET Framework 4.5 | ❌ | ✔ |
This method verifies if an Internet connection is available by sending a request on a website (https://bing.com). It returns a bool
value.
It's in:
LeoCorpLibrary.NetworkConnection.IsAvailableAsync()
Here's an example of usage:
C#
async void TestConnection()
{
bool connectionAvailable = await NetworkConnection.IsAvailableAsync();
}
VB
Private Async Sub TestConnection()
Dim connectionAvailable As Boolean = Await NetworkConnection.IsAvailableAsync()
End Sub
This method is avaialable in version 2.1 and higher.
Compatibility
Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
---|---|---|
.NET 5 | ✔ | ✔ |
.NET Core 3.1 | ✔ | ✔ |
.NET Framework 4.7.2 | ✔ | ✔ |
.NET Framework 4.5 | ❌ | ✔ |
This method verifies if an Internet connection is available by sending a request on a specified website. Returns a bool
value.
It's in:
LeoCorpLibrary.NetworkConnection.IsAvailableTestSiteAsync()
It has one argument:
Valeur | Paramètre | Description |
---|---|---|
string | site | URL of the website where the connection is tested |
Here's an example of usage:
C#
async void TestConnection()
{
bool connectionAvailable = await NetworkConnection.IsAvaialableTestSiteAsync("https://leocorp.fr");
}
VB
Private Async Sub TestConnection()
Dim connectionAvailable As Boolean = Await NetworkConnection.IsAvailableTestSiteAsync("https://leocorp.fr")
End Sub
© 2021 Léo Corporation and contributors