diff --git a/Kinvey-Xamarin/Offline/AbstractKinveyOfflineClientRequest.cs b/Kinvey-Xamarin/Offline/AbstractKinveyOfflineClientRequest.cs index 73bda29f..1e0788fd 100644 --- a/Kinvey-Xamarin/Offline/AbstractKinveyOfflineClientRequest.cs +++ b/Kinvey-Xamarin/Offline/AbstractKinveyOfflineClientRequest.cs @@ -16,6 +16,7 @@ using System.Threading.Tasks; using Newtonsoft.Json.Linq; using KinveyUtils; +using System.Reflection; namespace KinveyXamarin { @@ -213,9 +214,19 @@ public async override Task ExecuteAsync(){ /// Kicks off the background sync thread /// public void kickOffSync(){ - Task.Run (() => { - new BackgroundExecutor ((Client)Client).RunSync (); - }); + Type parameterType = typeof(T); + if (parameterType.IsArray) { + parameterType = parameterType.GetElementType (); + } + + Type executor = typeof(BackgroundExecutor<>); + Type gen = executor.MakeGenericType (parameterType); + + foreach (var ctor in gen.GetTypeInfo().DeclaredConstructors) { + Task.Run (() => { + ctor.Invoke (new object[1]{ (Client)Client }); + }); + } } /// diff --git a/Kinvey-Xamarin/Offline/BackgroundExecutor.cs b/Kinvey-Xamarin/Offline/BackgroundExecutor.cs index 7fcb9eab..02bfec1b 100644 --- a/Kinvey-Xamarin/Offline/BackgroundExecutor.cs +++ b/Kinvey-Xamarin/Offline/BackgroundExecutor.cs @@ -51,6 +51,7 @@ public BackgroundExecutor (Client client) this.dbpath = Path.Combine(client.filePath, "kinveyOffline.sqlite") ; this.platform = client.offline_platform; this.client = client; + RunSync (); } /// @@ -93,8 +94,7 @@ private async void buildAndExecuteRequest(DatabaseHelper handler, SQLTemplate switch (verb) { case "QUERY": - - break; + T[] results = await appdata.GetAsync (id); List idresults = new List(); foreach ( T ent in results){