public void GetObjectIsThreadSafe() { ObjectFactory = CreateObjectFactory(true); GenericObjectDefinition theSpouse = new GenericObjectDefinition(); theSpouse.ObjectTypeName = typeof(TestObject).FullName; theSpouse.IsSingleton = false; ObjectFactory.RegisterObjectDefinition("theSpouse", theSpouse); GenericObjectDefinition theObject = new GenericObjectDefinition(); theObject.ObjectTypeName = typeof(TestObject).FullName; theObject.IsSingleton = false; theObject.PropertyValues.Add("Spouse", theSpouse); ObjectFactory.RegisterObjectDefinition("theObject", theObject); AsyncTestTask t1 = new AsyncTestMethod(20000, new ThreadStart(GetTheTestObject)).Start(); AsyncTestTask t2 = new AsyncTestMethod(20000, new ThreadStart(GetTheTestObject)).Start(); AsyncTestTask t3 = new AsyncTestMethod(20000, new ThreadStart(GetTheTestObject)).Start(); AsyncTestTask t4 = new AsyncTestMethod(20000, new ThreadStart(GetTheTestObject)).Start(); t1.AssertNoException(); t2.AssertNoException(); t3.AssertNoException(); t4.AssertNoException(); }
static void Main(string[] args) { ApmDemoAsync adAsync = new ApmDemoAsync(); var resultAsync = adAsync.BeginTestMethod(1000); Console.WriteLine(adAsync.EndTestMethod(resultAsync)); ApmDemo ad = new ApmDemo(); var caller = new AsyncTestMethod(ad.TestMethod); IAsyncResult result = caller.BeginInvoke(3000, null, null); IAsyncResult result2 = caller.BeginInvoke(5000, null, null); IAsyncResult result3 = caller.BeginInvoke(7000, null, null); IAsyncResult result4 = caller.BeginInvoke(9000, x => Console.WriteLine(caller.EndInvoke(x)), null); while (!result.IsCompleted) { Thread.Sleep(1); } Console.WriteLine(caller.EndInvoke(result)); Console.WriteLine(caller.EndInvoke(result2)); while (!result3.AsyncWaitHandle.WaitOne(500)) { Console.WriteLine("Waiting for result3"); } Console.WriteLine(caller.EndInvoke(result3)); Console.ReadLine(); }
public static void CanAccessContextFromNonWebThreadImpl() { IApplicationContext ctx; ctx = WebApplicationContext.GetRootContext(); AsyncTestMethod testMethod = new AsyncTestMethod(1, new AsyncTestMethod.TestMethod(DoBackgroundWork), ctx); testMethod.Start(); testMethod.AssertNoException(); }
public void CurrentProxyIsThreadSafe() { ProxyTestObjectAndExposeProxy(); AsyncTestMethod t1 = new AsyncTestMethod(1000, new ThreadStart(ProxyTestObjectAndExposeProxy)); AsyncTestMethod t2 = new AsyncTestMethod(1000, new ThreadStart(ProxyTestObjectAndExposeProxy)); t1.Start(); t2.Start(); t1.AssertNoException(); t2.AssertNoException(); }
public void ProxyFactoryObjectIsThreadSafe() { const int WORKERS = 10; AsyncTestMethod[] workers = new AsyncTestMethod[WORKERS]; for (int i = 0; i < WORKERS; i++) { workers[i] = new AsyncTestMethod(1, new ThreadStart(CallGetObject)); } for (int i = 0; i < WORKERS; i++) { workers[i].Start(); } for (int i = 0; i < WORKERS; i++) { workers[i].AssertNoException(); } }
public ApmDemoAsync() { caller = TestMethod; }