Search code examples
c#microsoft-graph-apimicrosoft-graph-sdks

Set TimeOut in Microsoft.Graph SDK Version 5


On graph sdk v4, I use option to set TimeOut to a higher value in Microsoft.Graph GraphServiceClient like bellow.

graphServiceClient.HttpProvider.OverallTimeout = TimeSpan.FromSeconds(10);

However, updating to graph sdk v5, I notice this doesn't supported in our new graph sdk v5. How can I do this in the new graph version? Anyone please help me


Solution

  • Use GraphClientFactory to create a default HttpClient used by SDK and change Timeout.

    Then pass the instance of HttpClient to the ctor of GraphServiceClient

    var httpClient = GraphClientFactory.Create();
    httpClient.Timeout = TimeSpan.FromMinutes(5);
    var graphServiceClient = new GraphServiceClient(httpClient, tokenCredential);