Repeating a function in C# until it no longer throws an exception

后端 未结 11 2078
一生所求
一生所求 2021-01-18 00:31

I\'ve got a class that calls a SOAP interface, and gets an array of data back. However, if this request times out, it throws an exception. This is good. However, I want m

11条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-18 00:39

    If you can't change the timeout, the below should work. salesOrdersArray should be initialized to null.

    while(salesOrdersArray == null)
    {
        try
        {
           salesOrdersArray = MagServ.salesOrderList(sessID, filter);
        }
        catch
        {
           // Log failure
        }
    }
    

提交回复
热议问题