Problem: msdn forums: ActiveSync connection status
The description is as follows:
How to capture the current status of connecting to ActiveSync. For example, if there is a connection, it is true, and if there is no connection, it is false.
I have tried activesyncstatus. Synchronizing and systemstate. activesyncstatus.
Neither of them can determine whether the PDA is connected to ActiveSync.
Solution:
Use the systemstate. cradlepresent attribute: gets a value indicating whether the device is connected to a cradle.
When using Microsoft. windowsmobile, Microsoft. windowsmobile. status must be referenced.
Code
The following code retrieves and displays the status of the systemstate. cradlepresent attribute when a button is clicked:
Button#click
Using System;
Using System. LINQ;
Using System. Collections. Generic;
Using System. componentmodel;
Using System. Data;
Using System. drawing;
Using System. text;
Using System. Windows. forms;
Using Microsoft. windowsmobile. status;
Namespace Smartdeviceproject7
{
Public Partial Class Form1: Form
{
Public Form1 ()
{
Initializecomponent ();
}
Private Void Button#click ( Object Sender, eventargs E)
{
// Systemstate. cradlepresent: gets a value indicating whether the device is connected to a cradle.
Textbox1.text = Systemstate. cradlepresent. tostring ();
// False when no connection is established
// Show true when connecting lines
}
}
}
The following code gets and displays the status of the systemstate. cradlepresent attribute when the system status changes
Msystemstate_changed
Using System;
Using System. LINQ;
Using System. Collections. Generic;
Using System. componentmodel;
Using System. Data;
Using System. drawing;
Using System. text;
Using System. Windows. forms;
Using Microsoft. windowsmobile. status;
Namespace Smartdeviceproject7
{
Public Partial Class Form1: Form
{
Public Form1 ()
{
Initializecomponent ();
}
Systemstate msystemstate;
// Event triggered when the status changes
Void Msystemstate_changed ( Object Sender, changeeventargs ARGs)
{
// Systemstate. cradlepresent: gets a value indicating whether the device is connected to a cradle.
Textbox1.text = Systemstate. cradlepresent. tostring ();
// False when no connection is established
// Show true when connecting lines
}
Private Void Form1_load ( Object Sender, eventargs E)
{
// Add event
Msystemstate = New Systemstate (systemproperty. cradlepresent );
Msystemstate. Changed + = New Changeeventhandler (msystemstate_changed );
Msystemstate_changed ( Null , Null );
}
}
}
ArticleReference:
Systemstate. cradlepresent adequacy
How to Get ActiveSync status in smart device