在我的xamarin android服务中,我使用以下代码:
public override async void OnCreate()
{
base.OnCreate();
cts_gps = new CancellationTokenSource();
await gpsAsync(10000, cts_gps.Token);
}
async Task gpsAsync(int interval, System.Threading.CancellationToken token)
{
while (1 == 1)
{
try
{
await Task.Run(() =>
{
if (sobhan.CheckForInternetConnection(this))
{
sobhan.ac.RunOnUiThread(delegate
{
Toast.MakeText(this, "اینترنت متصل است", ToastLength.Short).Show();
});
if (!is_this_username)
if (sobhan.username == sobhan.ws.get_karbar_username().ToLower())
is_this_username = true;
if (is_this_username)
{
{some stuffs}
当服务被android停止并且要通过粘性重新运行时,我立即收到以下异常:
对象引用未设置为对象的实例 System.Collections.ListDictionaryInternal mscorlib -2147467261
在app_hidded.googlelocations.b__5_0()[0x0000f]中 :0处 System.Threading.Tasks.Task.InnerInvoke()[0x00012]在 <5fff7c93020c4cd3bb710c267fec60a1>:0在 System.Threading.Tasks.Task.Execute()[0x00016]在 <5fff7c93020c4cd3bb710c267fec60a1>:0 ---从上一个引发异常的位置开始的堆栈跟踪- System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在<5fff7c93020c4cd3bb710c267fec60a1>:0中的[0x0000c] System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task任务)[0x0004e]在 <5fff7c93020c4cd3bb710c267fec60a1>:0在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task任务)在[0x0002e]中 <5fff7c93020c4cd3bb710c267fec60a1>:0在 System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task任务)在[0x0000b]中 <5fff7c93020c4cd3bb710c267fec60a1>:0在 System.Runtime.CompilerServices.TaskAwaiter.GetResult()[0x00000]在 <5fff7c93020c4cd3bb710c267fec60a1>:0在 app_hidded.googlelocations + d__5.MoveNext()[0x00091]在 :0空投掷()
谢谢