同步探测本地星尘代理时,捕获超时异常,避免误导用户以为其它业务功能异常

This commit is contained in:
大石头 2022-03-03 19:21:20 +08:00
parent fc1a6d02d8
commit c97c8239f7
2 changed files with 17 additions and 2 deletions

View File

@ -60,7 +60,7 @@ namespace Stardust
/// <returns></returns>
public AgentInfo GetInfo()
{
var task = GetInfoAsync();
var task = GetInfoAsync().ContinueWith<AgentInfo>(t => null, TaskContinuationOptions.OnlyOnFaulted);
if (task.Wait(500)) return task.Result;
return null;

View File

@ -22,7 +22,7 @@ namespace Test
{
XTrace.UseConsole();
Test3();
Test6();
Console.WriteLine("OK!");
Console.ReadKey();
@ -146,5 +146,20 @@ namespace Test
XTrace.WriteLine(item.ToJson());
}
}
static async void Test6()
{
var client = new LocalStarClient();
client.GetInfo();
try
{
await client.GetInfoAsync();
}
catch (Exception ex)
{
XTrace.Log.Error("星尘探测失败!{0}", ex.Message);
}
}
}
}