Mvvmcross中使用Messenger插件的Sqlite异常

时间:2015-05-21 00:18:44

标签: sqlite xamarin touch mvvmcross

我在申请中面临以下崩溃:

 2015-05-20 21:07:55.950 App[88568:2654974] critical:   at (wrapper managed-to-native) SQLite.SQLite3.Prepare2 (intptr,string,int,intptr&,intptr) <IL 0x0003c, 0xffffffff>
 2015-05-20 21:07:55.950 App[88568:2654974] critical:   at SQLite.SQLite3.Prepare2 (intptr,string) <IL 0x0000f, 0x00067>
 2015-05-20 21:07:55.950 App[88568:2654974] critical:   at SQLite.SQLiteCommand.Prepare () <IL 0x00011, 0x0005f>
 2015-05-20 21:07:55.950 App[88568:2654974] critical:   at SQLite.SQLiteCommand/<ExecuteDeferredQuery>d__0`1.MoveNext () <IL 0x0003f, 0x000bf>
 2015-05-20 21:07:55.950 App[88568:2654974] critical:   at System.Collections.Generic.List`1.AddEnumerable (System.Collections.Generic.IEnumerable`1<T>) [0x00013] in /     Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Collections.Generic/List.cs:146
 2015-05-20 21:07:55.951 App[88568:2654974] critical:   at System.Collections.Generic.List`1..ctor (System.Collections.Generic.IEnumerable`1<T>) [0x0002f] in /Developer/     MonoTouch/Source/mono/mcs/class/corlib/System.Collections.Generic/List.cs:69
 2015-05-20 21:07:55.951 App[88568:2654974] critical:   at System.Linq.Enumerable.ToList<TSource> (System.Collections.Generic.IEnumerable`1<TSource>) [0x00006] in ///     Library/Frameworks/Xamarin.iOS.framework/Versions/8.9.1.3/src/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:2952
 2015-05-20 21:07:55.951 App[88568:2654974] critical:   at SQLite.SQLiteCommand.ExecuteQuery<T> () <IL 0x0001b, 0x0009b>
 2015-05-20 21:07:55.951 App[88568:2654974] critical:   at SQLite.SQLiteConnection.Query<T> (string,object[]) <IL 0x0000f, 0x000a3>
 2015-05-20 21:07:55.951 App[88568:2654974] critical:   at SQLite.SQLiteConnection.Get<T> (object) <IL 0x00024, 0x000d3>
 2015-05-20 21:07:55.951 App[88568:2654974] critical:   at App.Core.Services.DatabaseServices.DatabaseService.GetThread (string) [0x0001b] in /Users/gbastos/Documents/     Gabriel Docs/Development/App/App.Mobile.Core/Services/DatabaseServices/DatabaseService.cs:499
 2015-05-20 21:07:55.951 App[88568:2654974] critical:   at App.Core.ViewModels.ThreadsListViewModel.UpdateThreadList (App.Core.Messengers.DatabaseMessenger) [0x0010f] in /     Users/gbastos/Documents/Gabriel Docs/Development/App/App.Mobile.Core/ViewModels/ThreadsListViewModel.cs:219
 2015-05-20 21:07:55.952 App[88568:2654974] critical:   at Cirrious.MvvmCross.Plugins.Messenger.Subscriptions.WeakSubscription`1/<>c__DisplayClass1.<TypedInvoke>b__0 () <     IL 0x0000c, 0x00032>
 2015-05-20 21:07:55.952 App[88568:2654974] critical:   at Cirrious.CrossCore.Core.MvxMainThreadDispatcher.ExceptionMaskedAction (System.Action) <IL 0x00001, 0x00033>
 2015-05-20 21:07:55.952 App[88568:2654974] critical:   at Cirrious.MvvmCross.Touch.Views.MvxTouchUIThreadDispatcher/<>c__DisplayClass1.<RequestMainThreadAction>b__0 () <     IL 0x00006, 0x00027>
 2015-05-20 21:07:55.952 App[88568:2654974] critical:   at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Developer/MonoTouch/Source/maccore/src/Foundation/     NSAction.cs:164
 2015-05-20 21:07:55.952 App[88568:2654974] critical:   at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr) <IL 0x0004e,      0xffffffff>
 2015-05-20 21:07:55.952 App[88568:2654974] critical:   at <unknown> <0xffffffff>
 2015-05-20 21:07:55.952 App[88568:2654974] critical:   at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <IL 0x000a6,      0xffffffff>
 2015-05-20 21:07:55.952 App[88568:2654974] critical:   at UIKit.UIApplication.Main (string[],intptr,intptr) [0x00005] in /Developer/MonoTouch/Source/monotouch/src/UIKit/     UIApplication.cs:62
 2015-05-20 21:07:55.952 App[88568:2654974] critical:   at UIKit.UIApplication.Main (string[],string,string) [0x00038] in /Developer/MonoTouch/Source/monotouch/src/UIKit/     UIApplication.cs:46
 2015-05-20 21:07:55.953 App[88568:2654974] critical:   at App.Mobile.Touch.Application.Main (string[]) [0x00008] in /Users/gbastos/Documents/Gabriel Docs/Development/App/     App.Mobile.Touch/Main.cs:17
 2015-05-20 21:07:55.953 App[88568:2654974] critical:   at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>

我有一个ViewModel,它在MvxMessenger中的MainThread中有一个弱订阅。接收消息后调用的函数是调用我的数据库服务。但是我有可能在同一时间收到两条不同的消息。 (也许这是错误,已经为数据库服务添加了一个锁,但没有工作)

此错误仅在iOS中发生,但在Android或WPF中不发生。

是否有人有一些相关的错误?

这是我的DatabaseService获取线程代码:

public Thread GetThread(string threadId)
    {
        lock (DatabaseLockObject)
        {
            try
            {
                var a = _connection.Get<Thread> (threadId);
                return a;
            }
            catch (Exception)
            {
                return null;
            }
        }
    }

我的信使订阅是:

_subscriptionToken = messenger.SubscribeOnMainThread <DatabaseMessenger>(UpdateThreadList);

UpdateThreadList方法是:

    private void UpdateThreadList(DatabaseMessenger sender)
    {
            var message = (Message)sender.Value;
            var thread = _databaseService.GetThread(message.ThreadId);
            bool needUpdate = false;

            if(SharedSettings.AppSettings.GetValue(SharedSettings.Keys.CurrentThread.ToString(), "") != message.ThreadId
                && sender.Type != DatabaseMessenger.DatabaseMessageType.Delete  && message.Timestamp >= thread.SnippetTime && 
                message.SenderId != SharedSettings.AppSettings.GetValue(SharedSettings.Keys.UserInfoId.ToString(), "") && message.Id != _lastMessageId)
            {
                ++thread.UnreadMessagesCount;
                needUpdate = true;
                _lastMessageId = message.Id;
            }

            if(needUpdate)
            {
                _databaseService.Update(thread);
            }
        }
    }

谢谢, 加布里埃尔

0 个答案:

没有答案