Beispiel #1
0
        public void ListChangedEventIsAlwaysOnTheThreadThatCreatedTheList()
        {
            try
            {
                //convince the threadsafebindinglist we are using a synchronization context
                //by providing a synchronization context
                var context = new MockContext();
                SynchronizationContext.SetSynchronizationContext(context);

                var list = new ThreadsafeBindingList <int>(context);

                //create a new thread adding something to the list
                //use an anonymous lambda expression delegate :)
                var addFiveThread = new Thread(() =>
                {
                    list.Add(5);
                });
                //action! run the thread adding 5
                addFiveThread.Start();
                //wait for the other thread to finish
                while (addFiveThread.IsAlive)
                {
                    Thread.Sleep(10);
                }

                //assert the list used the context.
                Assert.AreEqual(1, context.SendWasCalled, "The list did not use the send method the current context!");
            }
            finally
            {
                //always reset the synchronizationcontext
                SynchronizationContext.SetSynchronizationContext(null);
            }
        }
        public void ListChangedEventIsAlwaysOnTheThreadThatCreatedTheList()
        {
            try
            {
                //convince the threadsafebindinglist we are using a synchronization context  
                //by providing a synchronization context
                var context = new MockContext();
                SynchronizationContext.SetSynchronizationContext(context);

                var list = new ThreadsafeBindingList<int>(context);

                //create a new thread adding something to the list
                //use an anonymous lambda expression delegate :)
                var addFiveThread = new Thread(() =>
                {
                    list.Add(5);
                });
                //action! run the thread adding 5
                addFiveThread.Start();
                //wait for the other thread to finish
                while (addFiveThread.IsAlive)
                    Thread.Sleep(10);

                //assert the list used the context.
                Assert.AreEqual(1, context.SendWasCalled, "The list did not use the send method the current context!");

            }
            finally
            {
                //always reset the synchronizationcontext
                SynchronizationContext.SetSynchronizationContext(null);
            }
            
        }
Beispiel #3
0
 public void ExceptionIsThrownIfASynchronizationContextIsNotAvailable()
 {
     var list = new ThreadsafeBindingList <int>(null);
 }
 public void ExceptionIsThrownIfASynchronizationContextIsNotAvailable()
 {
     var list = new ThreadsafeBindingList<int>(null);
 }