ConnectivityStatus.IsOffline Eigenschap
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee wordt een waarde opgehaald of ingesteld die aangeeft of een toepassing zich in de offlinemodus bevindt.
public:
static property bool IsOffline { bool get(); void set(bool value); };
public static bool IsOffline { get; set; }
static member IsOffline : bool with get, set
Public Shared Property IsOffline As Boolean
Waarde van eigenschap
true als de toepassing zich in de offlinemodus bevindt; anders, false.
Voorbeelden
In de volgende voorbeeldcode ziet u hoe u deze eigenschap gebruikt om de offlinestatus bij te werken, afhankelijk van een selectievakjewaarde. In dit voorbeeld werkt een CheckedChanged gebeurtenishandler de offlinestatus bij. Als de gebruiker de toepassing instelt op de onlinestatus, probeert de gebeurtenishandler de gebruiker opnieuw tevalideren. Als de verificatieserver echter niet beschikbaar is, retourneert de gebeurtenis-handler de toepassing naar de offlinestatus.
private void workOfflineCheckBox_CheckedChanged(
object sender, EventArgs e)
{
ConnectivityStatus.IsOffline = workOfflineCheckBox.Checked;
if (!ConnectivityStatus.IsOffline)
{
try
{
// Silently re-validate the user.
((ClientFormsIdentity)
System.Threading.Thread.CurrentPrincipal.Identity)
.RevalidateUser();
// If any settings have been changed locally, save the new
// new values to the Web settings service.
SaveSettings();
// If any settings have not been changed locally, check
// the Web settings service for updates.
Properties.Settings.Default.Reload();
}
catch (System.Net.WebException)
{
MessageBox.Show(
"Unable to access the authentication service. " +
Environment.NewLine + "Staying in offline mode.",
"Warning", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
workOfflineCheckBox.Checked = true;
}
}
}
Private Sub workOfflineCheckBox_CheckedChanged( _
ByVal sender As Object, ByVal e As EventArgs) _
Handles workOfflineCheckBox.CheckedChanged
ConnectivityStatus.IsOffline = workOfflineCheckBox.Checked
If Not ConnectivityStatus.IsOffline Then
Try
' Silently re-validate the user.
CType(System.Threading.Thread.CurrentPrincipal.Identity, _
ClientFormsIdentity).RevalidateUser()
' If any settings have been changed locally, save the new
' new values to the Web settings service.
SaveSettings()
' If any settings have not been changed locally, check
' the Web settings service for updates.
My.Settings.Reload()
Catch ex As System.Net.WebException
MessageBox.Show( _
"Unable to access the authentication service. " & _
Environment.NewLine + "Staying in offline mode.", _
"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
workOfflineCheckBox.Checked = True
End Try
End If
End Sub
Opmerkingen
Wanneer u de IsOffline eigenschap instelt, slaat de ConnectivityStatus klasse de waarde in de cache op in het lokale bestandssysteem. De clientserviceproviders in de System.Web.ClientServices.Providers naamruimte controleren deze waarde om te bepalen of de offline gegevenscache moet worden gebruikt in plaats van toegang te krijgen tot de bijbehorende Microsoft Ajax-verificatie, -rollen en -profielservices.