/// <summary> /// Method for fetching the <see cref="ServiceInformationDto"/>. This method can be used for connection checking. The call returns quickly /// and does not produce any noticeable server load. /// </summary> /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> public async Task <ServiceInformationDto> GetServiceInformation(CancellationToken cancellationToken = default) { var serviceInformation = await GetServiceInformationInternal(FetchBehavior.FetchAlways, cancellationToken).ConfigureAwait(false); _LastValidServiceInformation = serviceInformation; return(_LastValidServiceInformation); }
private async Task <ServiceInformationDto> GetServiceInformationInternal(FetchBehavior behavior, CancellationToken cancellationToken = default) { // This is an intentional race condition. Calling this method from multiple threads may lead to multiple calls to Get<ServiceInformation>(). // However, this would be rare and harmless, since it should always return the same result. It would be a lot more difficult to make this work without any races or blocking. // It is important to never set _LastValidServiceInformation to null anywhere to avoid possible null returns here due to the race condition. if (behavior == FetchBehavior.FetchAlways || _LastValidServiceInformation == null) { var serviceInformation = await _RestClient.Request <ServiceInformationDto>(RequestBuilder.CreateGet("ServiceInformation"), cancellationToken).ConfigureAwait(false); _LastValidServiceInformation = serviceInformation; } return(_LastValidServiceInformation); }