public static object CreateInMTA(Type type) { if (!MTAHelper.IsNoContextMTA()) { MTAHelper.MTARequest mTARequest = new MTAHelper.MTARequest(type); lock (MTAHelper.critSec) { if (!MTAHelper.workerThreadInitialized) { MTAHelper.InitWorkerThread(); MTAHelper.workerThreadInitialized = true; } int num = MTAHelper.reqList.Add(mTARequest); if (!MTAHelper.evtGo.Set()) { MTAHelper.reqList.RemoveAt(num); throw new ManagementException(RC.GetString("WORKER_THREAD_WAKEUP_FAILED")); } } mTARequest.evtDone.WaitOne(); if (mTARequest.exception == null) { return(mTARequest.createdObject); } else { throw mTARequest.exception; } } else { return(Activator.CreateInstance(type)); } }
public static object CreateInMTA(Type type) { if (!MTAHelper.IsNoContextMTA()) { MTAHelper.MTARequest mTARequest = new MTAHelper.MTARequest(type); lock (MTAHelper.critSec) { if (!MTAHelper.workerThreadInitialized) { MTAHelper.InitWorkerThread(); MTAHelper.workerThreadInitialized = true; } int num = MTAHelper.reqList.Add(mTARequest); if (!MTAHelper.evtGo.Set()) { MTAHelper.reqList.RemoveAt(num); throw new ManagementException(RC.GetString("WORKER_THREAD_WAKEUP_FAILED")); } } mTARequest.evtDone.WaitOne(); if (mTARequest.exception == null) { return mTARequest.createdObject; } else { throw mTARequest.exception; } } else { return Activator.CreateInstance(type); } }
private static void WorkerThread() { Label0: MTAHelper.evtGo.WaitOne(); while (true) { MTAHelper.MTARequest item = null; lock (MTAHelper.critSec) { if (MTAHelper.reqList.Count <= 0) { goto Label0; } else { item = (MTAHelper.MTARequest)MTAHelper.reqList[0]; MTAHelper.reqList.RemoveAt(0); } } try { try { item.createdObject = Activator.CreateInstance(item.typeToCreate); } catch (Exception exception1) { Exception exception = exception1; item.exception = exception; } } finally { item.evtDone.Set(); } } }