private void RelocateSinkRCWToMTA() { ThreadDispatch threadDispatch = new ThreadDispatch(new ThreadDispatch.ThreadWorkerMethodWithParam(this.RelocateSinkRCWToMTA_ThreadFuncion)); threadDispatch.Parameter = this; threadDispatch.Start(); }
void RelocateNamespaceRCWToMTA() { ThreadDispatch disp = new ThreadDispatch(new ThreadDispatch.ThreadWorkerMethodWithParam(RelocateNamespaceRCWToMTA_ThreadFuncion)); disp.Parameter = this; disp.Start(); }
public InstrumentedAssembly(Assembly assembly, SchemaNaming naming) { this.mapTypeToTypeInfo = new Hashtable(); SecurityHelper.UnmanagedCode.Demand(); this.naming = naming; Assembly precompiledAssembly = naming.PrecompiledAssembly; if (null == precompiledAssembly) { CSharpCodeProvider cSharpCodeProvider = new CSharpCodeProvider(); CompilerParameters compilerParameter = new CompilerParameters(); compilerParameter.GenerateInMemory = true; compilerParameter.ReferencedAssemblies.Add(assembly.Location); compilerParameter.ReferencedAssemblies.Add(typeof(BaseEvent).Assembly.Location); compilerParameter.ReferencedAssemblies.Add(typeof(Component).Assembly.Location); Type[] types = assembly.GetTypes(); for (int i = 0; i < (int)types.Length; i++) { Type type = types[i]; if (this.IsInstrumentedType(type)) { this.FindReferences(type, compilerParameter); } } string[] code = new string[1]; code[0] = naming.Code; CompilerResults compilerResult = cSharpCodeProvider.CompileAssemblyFromSource(compilerParameter, code); foreach (CompilerError error in compilerResult.Errors) { Console.WriteLine(error.ToString()); } if (!compilerResult.Errors.HasErrors) { precompiledAssembly = compilerResult.CompiledAssembly; } else { throw new Exception(RC.GetString("FAILED_TO_BUILD_GENERATED_ASSEMBLY")); } } Type type1 = precompiledAssembly.GetType("WMINET_Converter"); this.mapTypeToConverter = (Hashtable)type1.GetField("mapTypeToConverter").GetValue(null); if (MTAHelper.IsNoContextMTA()) { this.InitEventSource(this); return; } else { ThreadDispatch threadDispatch = new ThreadDispatch(new ThreadDispatch.ThreadWorkerMethodWithParam(this.InitEventSource)); threadDispatch.Parameter = this; threadDispatch.Start(); return; } }
void RelocateNamespaceRCWToMTA() { ThreadDispatch disp = new ThreadDispatch(new ThreadDispatch.ThreadWorkerMethodWithParam(RelocateNamespaceRCWToMTA_ThreadFuncion)); disp.Parameter = this; disp.Start( ); // Thread thread = new Thread(new ThreadStart(RelocateNamespaceRCWToMTA_ThreadFuncion)); // thread.ApartmentState = ApartmentState.MTA; // thread.Start(); // thread.Join(); }
public InstrumentedAssembly(Assembly assembly, SchemaNaming naming) { SecurityHelper.UnmanagedCode.Demand(); // Bug#112640 - Close off any potential use from anything but fully trusted code this.naming = naming; Assembly compiledAssembly = naming.PrecompiledAssembly; if (null == compiledAssembly) { CSharpCodeProvider provider = new CSharpCodeProvider(); ICodeCompiler compiler = provider.CreateCompiler(); CompilerParameters parameters = new CompilerParameters(); parameters.GenerateInMemory = true; parameters.ReferencedAssemblies.Add(assembly.Location); parameters.ReferencedAssemblies.Add(typeof(BaseEvent).Assembly.Location); parameters.ReferencedAssemblies.Add(typeof(System.ComponentModel.Component).Assembly.Location); // Must reference any base types in 'assembly' // TODO: Make this more restrictive. Only look at instrumented types. foreach (Type type in assembly.GetTypes()) { FindReferences(type, parameters); } CompilerResults results = compiler.CompileAssemblyFromSource(parameters, naming.Code); foreach (CompilerError err in results.Errors) { Console.WriteLine(err.ToString()); } compiledAssembly = results.CompiledAssembly; } Type dynType = compiledAssembly.GetType("WMINET_Converter"); mapTypeToConverter = (Hashtable)dynType.GetField("mapTypeToConverter").GetValue(null); // TODO: Is STA/MTA all we have to worry about? if (!MTAHelper.IsNoContextMTA()) // Bug#110141 - Checking for MTA is not enough. We need to make sure we are not in a COM+ Context { ThreadDispatch disp = new ThreadDispatch(new ThreadDispatch.ThreadWorkerMethodWithParam(InitEventSource)); disp.Parameter = this; disp.Start( ); // We are on an STA thread. Create the event source on an MTA // Thread thread = new Thread(new ThreadStart(InitEventSource)); // thread.ApartmentState = ApartmentState.MTA; // thread.Start(); // thread.Join(); } else { InitEventSource(this); } }
public InstrumentedAssembly(Assembly assembly, SchemaNaming naming) { SecurityHelper.UnmanagedCode.Demand(); // Bug#112640 - Close off any potential use from anything but fully trusted code this.naming = naming; Assembly compiledAssembly = naming.PrecompiledAssembly; if (null == compiledAssembly) { CSharpCodeProvider provider = new CSharpCodeProvider(); // ICodeCompiler compiler = provider.CreateCompiler(); CompilerParameters parameters = new CompilerParameters(); parameters.GenerateInMemory = true; parameters.ReferencedAssemblies.Add(assembly.Location); parameters.ReferencedAssemblies.Add(typeof(BaseEvent).Assembly.Location); parameters.ReferencedAssemblies.Add(typeof(System.ComponentModel.Component).Assembly.Location); // Must reference any base types in 'assembly' // foreach (Type type in assembly.GetTypes()) { // Only interested in instrumented types (VSQFE#2469) if (IsInstrumentedType(type)) { FindReferences(type, parameters); } } CompilerResults results = provider.CompileAssemblyFromSource(parameters, naming.Code); foreach (CompilerError err in results.Errors) { Console.WriteLine(err.ToString()); } if (results.Errors.HasErrors) { // we failed to compile the generated code - the compile error shows up on console but we need to throw throw new Exception(RC.GetString("FAILED_TO_BUILD_GENERATED_ASSEMBLY")); } compiledAssembly = results.CompiledAssembly; } Type dynType = compiledAssembly.GetType("WMINET_Converter"); mapTypeToConverter = (Hashtable)dynType.GetField("mapTypeToConverter").GetValue(null); // if (!MTAHelper.IsNoContextMTA()) // Bug#110141 - Checking for MTA is not enough. We need to make sure we are not in a COM+ Context { ThreadDispatch disp = new ThreadDispatch(new ThreadDispatch.ThreadWorkerMethodWithParam(InitEventSource)); disp.Parameter = this; disp.Start( ); // We are on an STA thread. Create the event source on an MTA // Thread thread = new Thread(new ThreadStart(InitEventSource)); // thread.ApartmentState = ApartmentState.MTA; // thread.Start(); // thread.Join(); } else { InitEventSource(this); } }
void RelocateNamespaceRCWToMTA() { ThreadDispatch disp = new ThreadDispatch(new ThreadDispatch.ThreadWorkerMethodWithParam(RelocateNamespaceRCWToMTA_ThreadFuncion)); disp.Parameter = this; disp.Start(); }