Exemple #1
0
 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));
     }
 }
Exemple #2
0
		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);
			}
		}
Exemple #3
0
        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();
                }
            }
        }