From 7dc885163c00c94debe8c554f89d1c05cde66e0c Mon Sep 17 00:00:00 2001 From: Jonathan Pobst Date: Tue, 25 Sep 2007 14:38:37 +0000 Subject: [PATCH] 2007-09-25 Jonathan Pobst * SynchronizationContext.cs: Implement SetSynchronizationContext. 2007-09-25 Jonathan Pobst * AsyncOperationManager.cs: Tie the SynchronizationContext here to SynchronizationContext.Current. 2007-09-25 Jonathan Pobst * AsyncOperationManagerTest.cs: Add test for SynchronizationContext. 2007-09-25 Jonathan Pobst * System_test.dll.sources: Added AsyncOperationManagerTest.cs. svn path=/trunk/mcs/; revision=86329 --- mcs/class/System/ChangeLog | 4 ++ .../AsyncOperationManager.cs | 16 ++--- .../System/System.ComponentModel/ChangeLog | 5 ++ mcs/class/System/System_test.dll.sources | 1 + .../AsyncOperationManagerTest.cs | 61 +++++++++++++++++++ .../Test/System.ComponentModel/ChangeLog | 4 ++ mcs/class/corlib/System.Threading/ChangeLog | 4 ++ .../SynchronizationContext.cs | 3 +- 8 files changed, 88 insertions(+), 10 deletions(-) create mode 100644 mcs/class/System/Test/System.ComponentModel/AsyncOperationManagerTest.cs diff --git a/mcs/class/System/ChangeLog b/mcs/class/System/ChangeLog index ca0ad8aae65..469df7602fc 100644 --- a/mcs/class/System/ChangeLog +++ b/mcs/class/System/ChangeLog @@ -1,3 +1,7 @@ +2007-09-25 Jonathan Pobst + + * System_test.dll.sources: Added AsyncOperationManagerTest.cs. + 2007-09-17 Gert Driesen * System_test.dll.sources: Added ComponentResourceManagerTest.cs. diff --git a/mcs/class/System/System.ComponentModel/AsyncOperationManager.cs b/mcs/class/System/System.ComponentModel/AsyncOperationManager.cs index 029f2ab1575..736788456c2 100644 --- a/mcs/class/System/System.ComponentModel/AsyncOperationManager.cs +++ b/mcs/class/System/System.ComponentModel/AsyncOperationManager.cs @@ -35,26 +35,26 @@ namespace System.ComponentModel { public static class AsyncOperationManager { - static readonly SynchronizationContext default_context; - static SynchronizationContext current_context; - static AsyncOperationManager () { - default_context = new SynchronizationContext (); - current_context = default_context; } [EditorBrowsable (EditorBrowsableState.Advanced)] public static SynchronizationContext SynchronizationContext { - get { return current_context; } + get { + if (SynchronizationContext.Current == null) + SynchronizationContext.SetSynchronizationContext (new SynchronizationContext ()); + + return SynchronizationContext.Current; + } [SecurityPermission (SecurityAction.LinkDemand)] - set { current_context = value != null ? value : default_context; } + set { SynchronizationContext.SetSynchronizationContext (value); } } public static AsyncOperation CreateOperation (object userSuppliedState) { return new AsyncOperation ( - current_context, userSuppliedState); + SynchronizationContext, userSuppliedState); } } } diff --git a/mcs/class/System/System.ComponentModel/ChangeLog b/mcs/class/System/System.ComponentModel/ChangeLog index 2d05b504d3a..ec7d01ed943 100644 --- a/mcs/class/System/System.ComponentModel/ChangeLog +++ b/mcs/class/System/System.ComponentModel/ChangeLog @@ -1,3 +1,8 @@ +2007-09-25 Jonathan Pobst + + * AsyncOperationManager.cs: Tie the SynchronizationContext here to + SynchronizationContext.Current. + 2007-09-17 Gert Driesen * ComponentResourceManager.cs: In ApplyResources, when culture is diff --git a/mcs/class/System/System_test.dll.sources b/mcs/class/System/System_test.dll.sources index 89fd5f9f780..6057e00b1fb 100644 --- a/mcs/class/System/System_test.dll.sources +++ b/mcs/class/System/System_test.dll.sources @@ -107,6 +107,7 @@ System.Collections.Specialized/OrderedDictionaryTest.cs System.Collections.Specialized/StringCollectionTest.cs System.Collections.Specialized/StringDictionaryTest.cs System.ComponentModel/ArrayConverterTests.cs +System.ComponentModel/AsyncOperationManagerTest.cs System.ComponentModel/AttributeProviderAttributeTest.cs System.ComponentModel/BackgroundWorkerTest.cs System.ComponentModel/BindingListTest.cs diff --git a/mcs/class/System/Test/System.ComponentModel/AsyncOperationManagerTest.cs b/mcs/class/System/Test/System.ComponentModel/AsyncOperationManagerTest.cs new file mode 100644 index 00000000000..4570e7e376b --- /dev/null +++ b/mcs/class/System/Test/System.ComponentModel/AsyncOperationManagerTest.cs @@ -0,0 +1,61 @@ +// +// AsyncOperationManager.cs +// +// Author: +// Jonathan Pobst +// +// Copyright (C) 2007 Novell, Inc. +// + +#if NET_2_0 + +using System; +using System.Threading; +using System.ComponentModel; +using System.Globalization; + +using NUnit.Framework; + +namespace MonoTests.System.ComponentModel +{ + [TestFixture] + public class AsyncOperationManagerTest + { + [Test] + public void SyncContext () + { + SynchronizationContext sc1 = new SynchronizationContext (); + SynchronizationContext sc2 = new SynchronizationContext (); + + Assert.IsNull (SynchronizationContext.Current, "A1"); + Assert.IsNotNull (AsyncOperationManager.SynchronizationContext, "A2"); + Assert.IsNotNull (SynchronizationContext.Current, "A3"); + + SynchronizationContext.SetSynchronizationContext (sc1); + + Assert.AreSame (sc1, SynchronizationContext.Current, "A4"); + Assert.AreSame (sc1, AsyncOperationManager.SynchronizationContext, "A5"); + + AsyncOperationManager.SynchronizationContext = sc2; + + Assert.AreSame (sc2, SynchronizationContext.Current, "A6"); + Assert.AreSame (sc2, AsyncOperationManager.SynchronizationContext, "A7"); + + SynchronizationContext.SetSynchronizationContext (null); + + Assert.IsNull (SynchronizationContext.Current, "A8"); + // This is a brand new one, not sc1 or sc2 + Assert.IsNotNull (AsyncOperationManager.SynchronizationContext, "A9"); + Assert.IsNotNull (SynchronizationContext.Current, "A10"); + + AsyncOperationManager.SynchronizationContext = null; + + Assert.IsNull (SynchronizationContext.Current, "A11"); + // This is a brand new one, not sc1 or sc2 + Assert.IsNotNull (AsyncOperationManager.SynchronizationContext, "A12"); + Assert.IsNotNull (SynchronizationContext.Current, "A13"); + } + } +} + +#endif diff --git a/mcs/class/System/Test/System.ComponentModel/ChangeLog b/mcs/class/System/Test/System.ComponentModel/ChangeLog index d4b9b83adfc..68228e0d2c4 100644 --- a/mcs/class/System/Test/System.ComponentModel/ChangeLog +++ b/mcs/class/System/Test/System.ComponentModel/ChangeLog @@ -1,3 +1,7 @@ +2007-09-25 Jonathan Pobst + + * AsyncOperationManagerTest.cs: Add test for SynchronizationContext. + 2007-09-17 Gert Driesen * ComponentResourceManagerTest.cs: Added tests for ctors, diff --git a/mcs/class/corlib/System.Threading/ChangeLog b/mcs/class/corlib/System.Threading/ChangeLog index 788ddfddd7c..e85813908c7 100644 --- a/mcs/class/corlib/System.Threading/ChangeLog +++ b/mcs/class/corlib/System.Threading/ChangeLog @@ -1,3 +1,7 @@ +2007-09-25 Jonathan Pobst + + * SynchronizationContext.cs: Implement SetSynchronizationContext. + 2007-09-06 Dick Porter * Timer.cs: Only hold a WeakReference to the runner thread, to diff --git a/mcs/class/corlib/System.Threading/SynchronizationContext.cs b/mcs/class/corlib/System.Threading/SynchronizationContext.cs index 6ede32d7624..9749f0f26ad 100644 --- a/mcs/class/corlib/System.Threading/SynchronizationContext.cs +++ b/mcs/class/corlib/System.Threading/SynchronizationContext.cs @@ -88,10 +88,9 @@ namespace System.Threading Send (d, state); } - [MonoTODO] public static void SetSynchronizationContext (SynchronizationContext syncContext) { - throw new NotImplementedException (); + currentContext = syncContext; } [MonoTODO] -- 2.25.1