我有一个依赖天蓝色服务的应用程序。在大多数情况下,它是无缝的,但我也被抛回(它被应用程序捕获,因此应用程序不会失败)
---抛出异常的上一个位置的堆栈跟踪结束---
在/Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:62中的System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()[0x0000b]中
在/Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Runtime.CompilerServices/TaskAwaiter.cs:60中的System.Runtime.CompilerServices.TaskAwaiter.GetResult()[0x00034]
在Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient + d__1c.MoveNext()[0x00000] in:0
---从抛出异常的先前位置开始的堆栈跟踪结束---
在/Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:62中的System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()[0x0000b]中
at System.Runtime.CompilerServices.TaskAwaiter 1[System.Net.Http.HttpResponseMessage].GetResult () [0x00034] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Runtime.CompilerServices/TaskAwaiter_T.cs:59
at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient+<RequestAsync>d__4.MoveNext () [0x00000] in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:62
at System.Runtime.CompilerServices.TaskAwaiter
1 [Microsoft.WindowsAzure.MobileServices.MobileServiceHttpResponse] .GetResult()[0x00034]在/Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Runtime中。 CompilerServices / TaskAwaiter_T.cs:59
在Microsoft.WindowsAzure.MobileServices.MobileServiceTable +&lt;&gt; c__DisplayClassf +&lt; b__e&gt; d__11.MoveNext()[0x00000] in:0
编辑 - 删除了一些堆栈跟踪
我用来发送到服务器的代码非常简单
public static async Task<bool> StoreData<T>(T obj) where T:IIdentity
{
if (!ftrackData.Online)
return false;
try
{
#if __IOS__
var test = await AppDelegate.MobileService.GetTable<T>().Where(t => t.id == obj.id).ToListAsync();
if (test.Count != 0)
await AppDelegate.MobileService.GetTable<T>().UpdateAsync(obj);
else
await AppDelegate.MobileService.GetTable<T>().InsertAsync(obj);
/*using (var <List<T>> test = AppDelegate.MobileService.GetTable<T>().Where(t => t.id == obj.id).ToListAsync())
{
var tmp = new List<T>();
test.ContinueWith((res) =>
{
tmp = res.Result;
if (tmp.Count != 0)
{
Console.WriteLine("updating data");
AppDelegate.MobileService.GetTable<T>().UpdateAsync(obj);
}
else
{
Console.WriteLine("inserting data");
AppDelegate.MobileService.GetTable<T>().InsertAsync(obj);
Console.WriteLine("data inserted");
}
});*/
#else
using (var<List<T>> test = ftrack2.Singleton.MobileService.GetTable<T>().Where(t => t.id == obj.id).ToListAsync())
{
var tmp = new List<T>();
test.ContinueWith((res) =>
{
tmp = res.Result;
if (tmp.Count != 0)
ftrack2.Singleton.MobileService.GetTable<T>().UpdateAsync(obj);
else
ftrack2.Singleton.MobileService.GetTable<T>().InsertAsync(obj);
});
}
#endif
return true;
}
catch (InvalidOperationException ex)
{
Console.WriteLine("Exception in StoreData thrown : {0}-{1}", ex.Message, ex.StackTrace);
return false;
}
}
注释掉的部分是另一种尝试,再一次,它起作用,但不能像异步那样工作。
我还能做些什么来确保我不从服务器那里得到这个回归吗?