ConnectionProfile.GetConnectivityIntervalsAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Retrieves connectivity intervals (start timestamp plus duration) for this profile within the specified time window.
public:
virtual IAsyncOperation<IVectorView<ConnectivityInterval ^> ^> ^ GetConnectivityIntervalsAsync(DateTime startTime, DateTime endTime, NetworkUsageStates states) = GetConnectivityIntervalsAsync;
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperation<IVectorView<ConnectivityInterval>> GetConnectivityIntervalsAsync(DateTime const& startTime, DateTime const& endTime, NetworkUsageStates const& states);
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperation<IReadOnlyList<ConnectivityInterval>> GetConnectivityIntervalsAsync(System.DateTimeOffset startTime, System.DateTimeOffset endTime, NetworkUsageStates states);
function getConnectivityIntervalsAsync(startTime, endTime, states)
Public Function GetConnectivityIntervalsAsync (startTime As DateTimeOffset, endTime As DateTimeOffset, states As NetworkUsageStates) As IAsyncOperation(Of IReadOnlyList(Of ConnectivityInterval))
Parameters
- startTime
- DateTime DateTimeOffset
The start time over which to retrieve data. Can be no more than 60 days prior to the current time.
- endTime
- DateTime DateTimeOffset
The end time over which to retrieve data.
- states
- NetworkUsageStates
The state of the connection profile for which usage data should be returned.
Returns
A list of ConnectivityInterval objects, each providing the connection start time and its duration.
- Attributes
Examples
Example pattern (C#):
var profile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
if (profile != null)
{
var end = DateTime.UtcNow;
var start = end - TimeSpan.FromHours(24);
var states = new Windows.Networking.Connectivity.NetworkUsageStates();
var intervals = await profile.GetConnectivityIntervalsAsync(start, end, states);
double connectedMinutes = intervals.Sum(i => i.ConnectionDuration.TotalMinutes);
// Optionally fetch usage and compute bytes per connected minute
}
Remarks
Usage considerations
- Correlate with GetNetworkUsageAsync for volume metrics. Intervals represent presence; usage tracks bytes.
- Align start/end times to reporting boundaries. Leading or trailing partial intervals are returned when the window cuts through an active connection.
- Empty result = no connectivity recorded in the window (not an error).
- Poll no more frequently than needed (typical aggregation windows: ≥ 15 minutes). Very fine polling wastes power.
- Utilization: Sum
ConnectionDurationacross intervals; divide by total wall-clock span to derive connected ratio. Overlay usage data to compute bytes per connected minute. - Historical limits (≤ 60 days) mirror usage API limits. Partition longer look-backs into allowed segments.
Note
For incremental collection, persist the end of the last fully closed interval boundary and resume from there to avoid recounting a still-active interval.