예제 #1
0
        private async Task LoadFileInBackgroundAsync(ExtendetFileInfo charfile, Action <CharHolder> afterLoad = null)
        {
            MainPage.Instance.EnableBusy();
            try
            {
                CharHolder newchar = await CharHolderIO.Load(charfile);

                AppModel.Instance.MainObject = (newchar);
                AppModel.Instance.RequestNavigation(ProjectPages.Char);
                afterLoad?.Invoke(newchar);
            }
            catch (Exception ex)
            {
                Log.Write("Error reading file", ex);
            }
            MainPage.Instance.DisableBusy();
        }
예제 #2
0
        private static void LoadFileInBackgroundSynchron(ExtendetFileInfo charfile, Action <CharHolder> afterLoad = null)
        {
            MainPage.Instance.EnableBusy();
            BackgroundWorker b = new BackgroundWorker();

            b.DoWork += async(object sender, DoWorkEventArgs e) =>
            {
                if (e.Argument is ExtendetFileInfo charfile)
                {
                    System.Threading.Thread.Sleep(1000);
                    try
                    {
                        e.Result = await CharHolderIO.Load(charfile);
                    }
                    catch (Exception ex)
                    {
                        Log.Write("Error reading file", ex);
                    }
                }
            };
            b.RunWorkerCompleted += (object sender, RunWorkerCompletedEventArgs e) =>
            {
                if (e.Result is CharHolder newchar)
                {
                    AppModel.Instance.MainObject = newchar;
                    System.Diagnostics.Debug.WriteLine("                           Admin1");
                    AppModel.Instance.RequestNavigation(ProjectPages.Char);
                    System.Diagnostics.Debug.WriteLine("                           Admin2");
                    afterLoad?.Invoke(newchar);
                    System.Diagnostics.Debug.WriteLine("                           Admin3");
                }
                MainPage.Instance.DisableBusy();
                System.Diagnostics.Debug.WriteLine("                           Admin4");
            };
            try
            {
                b.RunWorkerAsync(charfile);
            }
            catch (InvalidOperationException)
            {
                //TODO Report
            }
        }