这个问题可能与我前段时间问过的another question有关。但是,情况现在有所不同。
我目前正在使用Xamarin开发一个Android应用,该应用可通过Wi-Fi连接与某些包含传感器的自定义硬件进行通信。我的应用程序的工作是从硬件中检索传感器数据并将其存储在手机上不显示(因此不会进行渲染)。我想接收所有测量之间的等距时间距离的连续数据流。不幸的是,情况并非如此,下图清楚地显示了以下图表,该图表描述了一次又一次地获取测量值所花费的时间:
我最初的猜测是那些峰值(范围最大2500毫秒)与垃圾收集周期相关,因此决定进行一些实验。到目前为止,我尝试了以下有关内存堆和GC算法的组合:
这些参数的所有组合都会产生相似的结果。并发GC已启用。您是否还有其他想法可能导致这些时间峰值?
我使用的代码仍然与上一个问题中使用的代码相似:
[...]
int timeout = 1000;
while (ShootContinuously) {
FrameCounter++;
CancellationToken cancellationToken = new CancellationToken();
var task = GetDataAndUpdateUIForContinuousShootingAsync(MyDisplayPlot, FrameCounter, StartTime, mainPage);
if (await Task.WhenAny(task, Task.Delay(timeout, cancellationToken)) == task) {
// Task completed within timeout.
// Consider that the task may have faulted or been canceled.
// We re-await the task so that any exceptions/cancellation is rethrown.
await task;
} else { // timeout/cancellation logic
Debug.WriteLine("Task is taking too long!");
await Client.DisconnectAndStopReadTaskAsync();
Client = null;
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
GC.Collect();
GC.WaitForPendingFinalizers();
Client = new MyClientSocket();
await Client.ConnectAndStartReadTaskAsync();
continue;
}
}
await Client.DisconnectAndStopReadTaskAsync();
唯一的区别是,我不再执行任何UI更新。
我有时会看到以下输出:
> 04-10 18:17:12.501 D/Mono ( 8751): AOT: image 'System.IO.dll.so'
> not found: dlopen failed: library not found
> 04-10 18:17:12.503 D/Mono ( 8751): AOT: image
> '/Users/builder/jenkins/workspace/xamarin-android-d15-9/xamarin-android/external/mono/sdks/out/android-armeabi-v7a-release/lib/mono/aot-cache/arm/System.IO.dll.so'
> not found: dlopen failed: library not found
> 04-10 18:17:12.503 D/Mono ( 8751): Config attempting to
> parse: 'System.IO.dll.config'. 04-10 18:17:12.503 D/Mono ( 8751):
> Config attempting to parse:
> '/Users/builder/jenkins/workspace/xamarin-android-d15-9/xamarin-android/external/mono/sdks/out/android-armeabi-v7a-release/etc/mono/assemblies/System.IO/System.IO.config'.Loaded
> assembly: System.IO.dll [External]
这与我的问题有关吗?