62,041
社区成员
发帖
与我相关
我的任务
分享
System.AggregateException: One or more errors occurred. ---> System.Threading.Tasks.TaskCanceledException: A task was canceled.
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task`1.get_Result()
at Richon.CollectingCore.UploadingService.Post(String requestUri, String content)
---> (Inner Exception #0) System.Threading.Tasks.TaskCanceledException: A task was canceled.<---
One or more errors occurred.
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task`1.get_Result()
at Richon.CollectingCore.UploadingService.Post(String requestUri, String content)
private void uploadingLoop()
{
while (this._running)
{
int count = this._cache.Count;
if (count > 0)
{
for (int i = 0; i < count; i++)
{
var dev = this._cache[i];
if (dev != null && dev.HasEnergyInfo && dev.HasDevicePropertyInfo)
{
using (UploadingService service = new UploadingService())
{
service.Post(ConfigHelper.DeviceAcquire, dev.ToJson());
}
_cache.Remove(dev);
Thread.Sleep(300);
}
}
}
}
}
public void Post(string requestUri, string content)
{
var httpContent = new StringContent(content, Encoding.UTF8, "application/json");
HttpResponseMessage response = null;
try
{
response = this._httpClient.PostAsync(requestUri, httpContent).Result;
}
catch (Exception e)
{
TxtLogger.WriteError(e);
return;
}
}