2 using System.Threading;
3 using System.Runtime.Remoting;
4 using System.Runtime.Remoting.Activation;
5 using System.Runtime.Remoting.Contexts;
6 using System.Runtime.Remoting.Messaging;
8 public class MyContextAttribute: Attribute, IContextAttribute {
9 public void GetPropertiesForNewContext (IConstructionCallMessage msg)
13 public bool IsContextOK (Context ctx, IConstructionCallMessage msg)
19 // CBO class whose objects are always in the correct context
20 class UnlockedCbo : ContextBoundObject {
35 // CBO class whose objects are always out of context
37 class LockedCbo : UnlockedCbo {
40 class Mbr : MarshalByRefObject {
57 // warning CS0197 is expected several times
59 UnlockedCbo uc = new UnlockedCbo ();
60 Interlocked.Increment (ref uc.Counter);
63 LockedCbo lc = new LockedCbo ();
65 Interlocked.Increment (ref lc.Counter);
67 } catch (InvalidOperationException) {
76 Interlocked.Increment (ref m.Counter);
82 Mbr rm = (Mbr) CreateRemote (typeof (Mbr));
84 Interlocked.Increment (ref rm.Counter);
86 } catch (InvalidOperationException) {
97 static object CreateRemote (Type t)
99 AppDomain d = AppDomain.CreateDomain ("foo");
100 return d.CreateInstanceAndUnwrap (t.Assembly.FullName, t.FullName);