You can separately configure business parameters and runtime parameters in Alibaba Cloud Darabonba SDK for .NET. The priority levels of the timeout periods that can be configured in the Darabonba SDK are listed in descending order: the timeout period that you configure by using RuntimeOptions, the timeout period that you configure when you initialize the SDK client, and the default timeout periods. The default timeout period for connection requests is 5 seconds, and the default timeout period for read requests is 10 seconds.
public static void Main(string[] args)
{
AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
{
// Your AccessKey ID.
AccessKeyId = accessKeyId,
// Your AccessKey secret.
AccessKeySecret = accessKeySecret,
};
// Configure a timeout period when you initialize an SDK client.
// The default timeout period for connection requests is 5,000 milliseconds. The value is calculated by using the formula: 5 × 1,000 = 5,000.
config.ConnectTimeout = connectionTimeoutMillis;
// The default timeout period for read requests is 10,000 milliseconds. The value is calculated by using the formula: 10 × 1,000 = 10,000.
config.ReadTimeout = readTimeoutMillis;
config.Endpoint = "ecs-cn-hangzhou.aliyuncs.com";
AlibabaCloud.SDK.Ecs20140526.Client client = new AlibabaCloud.SDK.Ecs20140526.Client(config);
// Configure a timeout period by using runtime parameters. The setting takes effect only on the requests that use the RuntimeOptions instance.
RuntimeOptions runtimeOptions = new RuntimeOptions();
runtimeOptions.ConnectTimeout = connectionTimeoutMillis;
runtimeOptions.ReadTimeout = readTimeoutMillis;
DescribeInstancesRequest request = new DescribeInstancesRequest();
// Process HTTP requests to serialize the return result into a response object in the SDK based on the core library.
var response = client.DescribeInstancesWithOptions(request, runtimeOptions);
System.Console.WriteLine(response.Body.TotalCount);
}