예제 #1
0
파일: Context.cs 프로젝트: hazzik/Rhino.Net
		internal static Rhino.Context Enter(Rhino.Context cx, ContextFactory factory)
		{
			object helper = VMBridge.instance.GetThreadContextHelper();
			Rhino.Context old = VMBridge.instance.GetContext(helper);
			if (old != null)
			{
				cx = old;
			}
			else
			{
				if (cx == null)
				{
					cx = factory.MakeContext();
					if (cx.enterCount != 0)
					{
						throw new InvalidOperationException("factory.makeContext() returned Context instance already associated with some thread");
					}
					factory.OnContextCreated(cx);
					if (factory.IsSealed() && !cx.IsSealed())
					{
						cx.Seal(null);
					}
				}
				else
				{
					if (cx.enterCount != 0)
					{
						throw new InvalidOperationException("can not use Context instance already associated with some thread");
					}
				}
				VMBridge.instance.SetContext(helper, cx);
			}
			++cx.enterCount;
			return cx;
		}