ConnectivityStatus.IsOffline Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Recebe ou define um valor que indica se uma aplicação está em modo offline.
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
Valor de Propriedade
true se a aplicação estiver em modo offline; caso contrário, false.
Exemplos
O seguinte exemplo de código demonstra como usar esta propriedade para atualizar o estado offline dependendo do valor de uma caixa de seleção. Neste exemplo, um CheckedChanged gestor de eventos atualiza o estado offline. Se o utilizador definir a aplicação para o estado online, o gestor de eventos tenta revalidar o utilizador. No entanto, se o servidor de autenticação não estiver disponível, o gestor de eventos devolve a aplicação ao estado offline.
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
Observações
Quando defines a IsOffline propriedade, a ConnectivityStatus classe armazena o valor em cache no sistema de ficheiros local. Os fornecedores de serviços cliente no espaço de nomes System.Web.ClientServices.Providers verificam este valor para determinar se devem usar a cache de dados offline em vez de tentarem aceder aos serviços associados de autenticação Microsoft Ajax, funções e perfis.