簡體   English   中英

.NET Core / .NET Standard 2.0中的ReliableSession / MaxRetryCount

[英]ReliableSession / MaxRetryCount in .NET Core / .NET Standard 2.0

我已將Connected Service(WCF客戶端)添加到.NET Standard 2.0項目中。

我正在嘗試設置wcf綁定,以便當出現Communication Exception時,它將重試該請求。 https://stackoverflow.com/a/1968874/475727之類的東西

如何在.NET Standard 2.0中進行操作?

.NET Core尚不支持可靠的會話。 從某種意義上來說,您基本上是自己一個人,您需要實現其背后的業務邏輯。 也許這可以幫助您:

public static void Retry(int retryCount, TimeSpan delay, Action action)
    {
        bool b = Retry<bool>(
            retryCount,
            delay,
            () => { action(); return true; });
    }

    public static T Retry<T>(int retryCount, TimeSpan delay, Func<T> func)
    {
        int currentAttempt = 0;

        while (true)
        {
            try
            {
                ++currentAttempt;
                return func();
            }
            catch
            {
                if (currentAttempt == retryCount)
                {
                    throw;
                }
            }

            if (delay > TimeSpan.Zero)
            {
                Thread.Sleep(delay);
            }
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM