MonoDevelop.Projects.Formats.MSBuild.BuildEngine.RunSTA C# (CSharp) Method

RunSTA() static private method

static private RunSTA ( ThreadStart ts ) : void
ts ThreadStart
return void
		internal static void RunSTA (ThreadStart ts)
		{
			lock (workLock) {
				lock (threadLock) {
					workDelegate = ts;
					workError = null;
					if (workThread == null) {
						workThread = new Thread (STARunner);
						workThread.SetApartmentState (ApartmentState.STA);
						workThread.IsBackground = true;
						workThread.CurrentUICulture = uiCulture;
						workThread.Start ();
					}
					else
						// Awaken the existing thread
						Monitor.Pulse (threadLock);
				}
				workDoneEvent.WaitOne ();
			}
			if (workError != null)
				throw new Exception ("MSBuild operation failed", workError);
		}

Usage Example

Example #1
0
        public MSBuildResult[] RunTarget(string target, ProjectConfigurationInfo[] configurations, ILogWriter logWriter,
                                         MSBuildVerbosity verbosity)
        {
            MSBuildResult[] result = null;
            BuildEngine.RunSTA(delegate
            {
                try {
                    var project      = SetupProject(configurations);
                    currentLogWriter = logWriter;

                    LocalLogger logger = new LocalLogger(Path.GetDirectoryName(file));
                    engine.UnregisterAllLoggers();
                    engine.RegisterLogger(logger);
                    engine.RegisterLogger(consoleLogger);

                    consoleLogger.Verbosity = GetVerbosity(verbosity);

                    // We are using this BuildProject overload and the BuildSettings.None argument as a workaround to
                    // an xbuild bug which causes references to not be resolved after the project has been built once.
                    engine.BuildProject(project, new string[] { target }, new Hashtable(), BuildSettings.None);

                    result = logger.BuildResult.ToArray();
                } catch (InvalidProjectFileException ex) {
                    result = new MSBuildResult[] { new MSBuildResult(false, ex.ProjectFile ?? file, ex.LineNumber, ex.ColumnNumber, ex.ErrorCode, ex.Message) };
                } finally {
                    currentLogWriter = null;
                }
            });
            return(result);
        }
All Usage Examples Of MonoDevelop.Projects.Formats.MSBuild.BuildEngine::RunSTA