Beispiel #1
0
 private static void CreateObjects(ICollection <ExampleObject> list, int n = 10)
 {
     for (int i = 0; i < n; i++)
     {
         list.Add(ExampleObject.CreateRandom());
     }
 }
Beispiel #2
0
        /// <summary>
        /// Updates the table.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The event.
        /// </param>
        private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
        {
            var vm = (ExampleViewModel)this.DataContext;

            Task.Factory.StartNew(() =>
            {
                for (var i = 0; i < 25; i++)
                {
                    lock (syncRoot)
                    {
                        vm.ItemsSource.Add(ExampleObject.CreateRandom());
                    }

                    Thread.Sleep(250);
                }
            });
        }
Beispiel #3
0
        /// <summary>
        /// Updates the table.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The event.
        /// </param>
        private void BtnReplace_OnClick(object sender, RoutedEventArgs e)
        {
            var vm = (ExampleViewModel)this.DataContext;

            var n = vm.ItemsSource.Count;

            Task.Factory.StartNew(() =>
            {
                lock (syncRoot)
                {
                    vm.ItemsSource.Clear();
                }

                for (var i = 0; i < n; i++)
                {
                    lock (syncRoot)
                    {
                        vm.ItemsSource.Add(ExampleObject.CreateRandom());
                    }
                }
            });
        }