我在后台执行长任务,可能需要几分钟或几小时,因此我会定期运行此任务……每30分钟执行一次重复任务:
NSTimer.CreateRepeatingScheduledTimer(SyncIntervalSeconds, (obj) =>
{
DataOfNextSync = DataOfNextSync.AddSeconds(SyncIntervalSeconds);
System.Threading.Tasks.Task.Run(() =>
{
syncService.FullDataSync();
});
});
在“完全同步”内部,我使用 HttpClient 和 SQLite 数据库,从服务器获取一些信息并将其放入我的数据库中,然后将某些文件保存在磁盘上
通常情况下一切正常,但是在某些情况下,我不知道为什么(通常在mac机处于睡眠状态时,并非总是如此),任务停止并显示以下错误消息:
System.AggregateException:发生一个或多个错误。 ---> System.Net.Http.HttpRequestException:发送请求时发生错误---> System.Net.WebException:错误:NameResolutionFailure 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/System/System.Net/WebConnection中的System.Net.WebConnection + d__16.MoveNext()[0x0002c] .cs:137 ---从之前引发异常的位置开始的堆栈结束跟踪--- 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class中的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task任务)[0x00037] /referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class中的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task任务)[0x00028]处/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class中的System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(System.Threading.Tasks.Task任务)[0x00008] /referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/referencesource/mscorlib/system中的System.Runtime.CompilerServices.ConfiguredTaskAwaitable + ConfiguredTaskAwaiter.GetResult()[0x00000] /runtime/compilerservices/TaskAwaiter.cs:447 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/System/System.Net/WebConnection中的System.Net.WebConnection + d__19.MoveNext()[0x000cc] .cs:259 ---从之前引发异常的位置开始的堆栈结束跟踪--- 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class中的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task任务)[0x00037] /referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class中的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task任务)[0x00028]处/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class中的System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(System.Threading.Tasks.Task任务)[0x00008] /referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 在System.Runtime.CompilerServices.ConfiguredTaskAwaitable
1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535 at System.Net.WebOperation+<Run>d__57.MoveNext () [0x00052] in /Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/System/System.Net/WebOperation.cs:268 --- End of stack trace from previous location where exception was thrown --- at System.Net.WebCompletionSource
1 + d__15 [T] .MoveNext()[0x0008e]中的/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/ mcs / class / System / System.Net / WebCompletionSource.cs:111 ---从之前引发异常的位置开始的堆栈结束跟踪--- 在System.Net.HttpWebRequest + d__2411[T].MoveNext () [0x000b5] in /Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/System/System.Net/HttpWebRequest.cs:952 --- End of stack trace from previous location where exception was thrown --- at System.Net.HttpWebRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x00018] in /Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/System/System.Net/HttpWebRequest.cs:1180 at System.Threading.Tasks.TaskFactory
1 [TResult] .FromAsyncCoreLogic(System.IAsyncResult iar,System.Func2[T,TResult] endFunction, System.Action
1 [T] endAction,System.Threading.Tasks.Task {{1} } /Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/referencesource/mscorlib/system/runtime/中的1 + ConfiguredTaskAwaiter [TResult] .GetResult()[0x00000]编译器服务/TaskAwaiter.cs:535 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/System.Net.Http中的System.Net.Http.HttpClientHandler + d__64.MoveNext()[0x003d3] /System.Net.Http/HttpClientHandler.cs:402 ---内部异常堆栈跟踪的结尾--- 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/System.Net.Http中的System.Net.Http.HttpClientHandler + d__64.MoveNext()[0x0046c] /System.Net.Http/HttpClientHandler.cs:406 ---从之前引发异常的位置开始的堆栈结束跟踪--- 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class中的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task任务)[0x00037] /referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class中的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task任务)[0x00028]处/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class中的System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(System.Threading.Tasks.Task任务)[0x00008] /referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin中的System.Runtime.CompilerServices.ConfiguredTaskAwaitable1[TResult] promise, System.Boolean requiresSynchronization) [0x0000f] in /Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/referencesource/mscorlib/system/threading/Tasks/FutureFactory.cs:550 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 at System.Runtime.CompilerServices.ConfiguredTaskAwaitable
1 [TResult] .GetResultCore(System.Boolean waitCompletionNotification)[0x0002b]中。 Mac / mcs / class / referencesource / mscorlib / system / threading / Tasks / Future.cs:562 在<2162774b92f2416e98dc5d9fc831c8f3>:0中的System.Threading.Tasks.Task1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535 at System.Net.Http.HttpClient+<SendAsyncWorker>d__46.MoveNext () [0x00080] in /Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/System.Net.Http/System.Net.Http/HttpClient.cs:276 --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00013] in /Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:2166 at System.Threading.Tasks.Task
2 [TKey,TValue]标头)[0x00080]中 在<2162774b92f2416e98dc5d9fc831c8f3>:0中的Aptos.Core.SynchronizationService.DownloadImage(SQLite.SQLiteConnection conn,System.Collections.Generic.Dictionary1[TResult].get_Result () [0x00000] in /Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/referencesource/mscorlib/system/threading/Tasks/Future.cs:532 at Aptos.Core.APIProvider.Get (System.String url, System.Collections.Generic.Dictionary
2 [TKey,TValue]标头)[0x008ba]中 --->(内部异常#0)System.Net.Http.HttpRequestException:发送请求时发生错误---> System.Net.WebException:错误:NameResolutionFailure 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/System/System.Net/WebConnection中的System.Net.WebConnection + d__16.MoveNext()[0x0002c] .cs:137 ---从之前引发异常的位置开始的堆栈结束跟踪--- 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class中的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task任务)[0x00037] /referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class中的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task任务)[0x00028]处/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class中的System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(System.Threading.Tasks.Task任务)[0x00008] /referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/referencesource/mscorlib/system中的System.Runtime.CompilerServices.ConfiguredTaskAwaitable + ConfiguredTaskAwaiter.GetResult()[0x00000] /runtime/compilerservices/TaskAwaiter.cs:447 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/System/System.Net/WebConnection中的System.Net.WebConnection + d__19.MoveNext()[0x000cc] .cs:259 ---从之前引发异常的位置开始的堆栈结束跟踪--- 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class中的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task任务)[0x00037] /referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class中的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task任务)[0x00028]处/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class中的System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(System.Threading.Tasks.Task任务)[0x00008] /referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 在System.Runtime.CompilerServices.ConfiguredTaskAwaitable2[TKey,TValue] headers, Aptos.Core.PatientImage newimage, System.String oldRelPath, System.Boolean isImport) [0x00097] in <2162774b92f2416e98dc5d9fc831c8f3>:0 at Aptos.Core.SynchronizationService.GetAllChanges (System.Collections.Generic.Dictionary
1 + d__15 [T] .MoveNext()[0x0008e]中的/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/ mcs / class / System / System.Net / WebCompletionSource.cs:111 ---从之前引发异常的位置开始的堆栈结束跟踪--- 在System.Net.HttpWebRequest + d__2411+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535 at System.Net.WebOperation+<Run>d__57.MoveNext () [0x00052] in /Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/System/System.Net/WebOperation.cs:268 --- End of stack trace from previous location where exception was thrown --- at System.Net.WebCompletionSource
1 [TResult] .FromAsyncCoreLogic(System.IAsyncResult iar,System.Func1[T].MoveNext () [0x000b5] in /Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/System/System.Net/HttpWebRequest.cs:952 --- End of stack trace from previous location where exception was thrown --- at System.Net.HttpWebRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x00018] in /Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/System/System.Net/HttpWebRequest.cs:1180 at System.Threading.Tasks.TaskFactory
1 [T] endAction,System.Threading.Tasks.Task {{1} } /Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/referencesource/mscorlib/system/runtime/中的1 + ConfiguredTaskAwaiter [TResult] .GetResult()[0x00000]编译器服务/TaskAwaiter.cs:535 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/System.Net.Http中的System.Net.Http.HttpClientHandler + d__64.MoveNext()[0x003d3] /System.Net.Http/HttpClientHandler.cs:402 ---内部异常堆栈跟踪的结尾--- 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/System.Net.Http中的System.Net.Http.HttpClientHandler + d__64.MoveNext()[0x0046c] /System.Net.Http/HttpClientHandler.cs:406 ---从之前引发异常的位置开始的堆栈结束跟踪--- 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class中的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task任务)[0x00037] /referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class中的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task任务)[0x00028]处/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class中的System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(System.Threading.Tasks.Task任务)[0x00008] /referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 在System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1 + ConfiguredTaskAwaiter [TResult] .GetResult()[0x00000]在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/中referencesource / mscorlib / system / runtime / compilerservices / TaskAwaiter.cs:535 在/Library/Frameworks/Xamarin.Mac.framework/Versions/5.0.0.0/src/Xamarin.Mac/mcs/class/System.Net.Http中的System.Net.Http.HttpClient + d__46.MoveNext()[0x00080] /System.Net.Http/HttpClient.cs:276 <---