gpt4 book ai didi

c# - .NET Core/.NET Standard 2.0 中的 ReliableSession/MaxRetryCount

转载 作者:太空宇宙 更新时间:2023-11-03 12:16:59 26 4
gpt4 key购买 nike

我已将连接服务(WCF 客户端)添加到 .NET Standard 2.0 项目中。

我正在尝试设置 wcf 绑定(bind),以便在出现通信异常时重试请求。类似于 https://stackoverflow.com/a/1968874/475727

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

最佳答案

.NET Core 尚不支持可靠 session 。从需要实现其背后的业务逻辑的意义上说,您基本上只能靠自己了。也许这对您有帮助:

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);
}
}
}

关于c# - .NET Core/.NET Standard 2.0 中的 ReliableSession/MaxRetryCount,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49304704/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com