gpt4 book ai didi

c# - 如何修复捕获 TimeoutException?

转载 作者:行者123 更新时间:2023-11-30 21:27:44 26 4
gpt4 key购买 nike

<分区>

如何捕获TimeoutException

我想在 3 秒后捕获 TimeoutException。但 3 秒后它打印出 TimeoutExceptionIt 太长了。超时! 预计。

使用控制台应用程序,它不会捕获TimeoutException

public static void work()
{
Thread.Sleep(3000);
Console.WriteLine("TimeoutException");
throw new TimeoutException();
}

public static void Main(string[] args)
{
try
{
ThreadStart th = new ThreadStart(work);
Thread t = new Thread(th);
t.Start();
//Execute SearchProgram
t.Abort();
}
catch (ThreadInterruptedException)
{
Console.WriteLine("It's too long. Timeout!");
}

Console.WriteLine("Result : ~~~");
}

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