Example #1
0
 public async void Fill(string header, byte i)
 {
     OnLoadWords.Invoke();
     if (taskRunFill?.Status == TaskStatus.Running)
     {
         tokenSource.Cancel();
     }
     await(taskRunFill = Task.Run(() =>
                                  Dispatcher.Invoke(async() =>
     {
         DataContext = new Story()
         {
             Name = header
         };
         WordTranslate.Items.Clear();
         var words  = Work.bd.Words.Where(w => w.TypeID == i);
         Count.Text = words.Count().ToString();
         await Task.Run(() =>
         {
             words.OrderBy(a => a.Text).AsParallel().AsOrdered().
             ForAll(w => Dispatcher.Invoke(() => WordTranslate.Items.Add(w)));
             Dispatcher.Invoke(() => UnLoadWords.Invoke());
         }, tokenSource.Token);
     }), tokenSource.Token));
 }
Example #2
0
        public async void Fill(Story s)
        {
            OnLoadWords.Invoke();
            if (taskRunFill?.Status == TaskStatus.Running)
            {
                tokenSource.Cancel();
            }
            await(taskRunFill = Task.Run(() =>
            {
                if (s == null)
                {
                    return;
                }
                Dispatcher.Invoke(async() =>
                {
                    DataContext = s;
                    WordTranslate.Items.Clear();

                    var swords = s.Story_Word.Where(sw => sw.Word.TypeID == null || sw.Word?.TypeID == 1);
                    Count.Text = swords.Count().ToString();
                    await Task.Run(() =>
                    {
                        swords.OrderBy(sw => sw.Word.Text).AsParallel().AsOrdered().
                        ForAll(sw => Dispatcher.Invoke(() => WordTranslate.Items.Add(sw?.Word)));
                        Dispatcher.Invoke(() => UnLoadWords.Invoke());
                    }, tokenSource.Token);
                });
            }, tokenSource.Token));
        }