public void Refresh() { try { lock (_lock) { IsCurrentlyRefresh = true; if (null != RotItems) { RotItems.Dispose(); } RotItems = RunningObjectTable.GetActiveProxyInformations("", ""); AddItems(); RemoveItems(); } } catch (Exception) { throw; } finally { IsCurrentlyRefresh = false; } }
static void Main(string[] args) { var t = new Thread(() => { using (var rw = new RunningObjectTable()) { IRegFreeComRotClass rc = new RegFreeComRotClass(); if (rw.RegisterObject(rc, typeof(IRegFreeComRotClass).FullName) != 0) { Console.WriteLine("RegisterObject MyDbgToolObject failed"); return; } // This thread // needs to remain active as long as the object is in the ROT because // this thread will server the requests (function calls). Console.WriteLine("Object is in ROT"); MSG msg; while (NativeMethods.GetMessage(out msg, IntPtr.Zero, 0, 0)) { // if wm_quit received, object gets revoked from rot as using block exits. // Thread (even process) can also exit. NativeMethods.TranslateMessage(ref msg); NativeMethods.DispatchMessage(ref msg); } } }); t.SetApartmentState(ApartmentState.STA); t.Start(); t.Join(); Console.ReadKey(); }
static void Main(string[] args) { Console.WriteLine($"开始创建wpp进程,目标个数:{Environment.ProcessorCount * 2}"); var initFiles = Directory.GetFiles(@"C:\Remote\Test"); foreach (string path in initFiles.Take(Environment.ProcessorCount * 2)) { var process = Process.Start(new ProcessStartInfo { FileName = WppPath, Arguments = $"{WppArgs} \"{path}\"", CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden }); process.WaitForInputIdle(); } Console.WriteLine("让进程飞一会"); Thread.Sleep(5000); Console.WriteLine("开始获取操作对象"); var list = RunningObjectTable.GetPresentationsList(); //待处理的文件数,100个文件,模拟并发 var filePaths = Directory.GetFiles(@"C:\Remote\Input"); List <TestResult> testResults = new List <TestResult>(); for (int count = 1; count <= list.Count; count++) { TestResult result = new TestResult(); result.WppCount = count; Console.WriteLine($"{count}进程开始"); Stopwatch stopwatch = Stopwatch.StartNew(); ConcurrentStack <string> stack = new ConcurrentStack <string>(filePaths); DirectoryInfo dir = new DirectoryInfo(@"C:\Remote\Output\"); dir.Create(); long totalElapsed = 0; Parallel.ForEach(list.Take(count), presentations => { while (stack.TryPop(out string path)) { Stopwatch swatch = Stopwatch.StartNew(); var pres = presentations.Open(path); string fileName = Path.Combine(dir.FullName, $"{Path.GetFileNameWithoutExtension(path)}.pdf"); pres.SaveCopyAs(fileName, PpSaveAsFileType.ppSaveAsPDF); pres.Close(); swatch.Stop(); totalElapsed += swatch.ElapsedMilliseconds; Console.WriteLine($"{count}-单文件“{Path.GetFileName(path)}”转换成功,耗时:{swatch.ElapsedMilliseconds}ms,时间:{DateTime.Now.ToString("mm:ss")}"); } });
public static void NRL() { try { // Current AutoCAD Document, Database and Editor. Autodesk.AutoCAD.ApplicationServices.Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; // Get running Visual Studio instances (using helper class). IDictionary <string, _DTE> vsInstances = RunningObjectTable.GetRunningVSIDETable(); // Check for no Visual Studio instances. if (vsInstances.Count == 0) { ed.WriteMessage("\nNo running Visual Studio instances were found. *Cancel*"); return; } // Create list of solution names. List <string> solNames = new List <string>(); foreach (KeyValuePair <string, _DTE> item in vsInstances) { solNames.Add(Path.GetFileNameWithoutExtension(item.Value.Solution.FullName)); } // Check if all solution names equal "". // i.e. no solutions loaded in any of the Visual Studio instances. bool allSolNamesEmpty = true; foreach (string name in solNames) { if (name != "") { allSolNamesEmpty = false; break; } } if (allSolNamesEmpty == true) { ed.WriteMessage("\nNo active Visual Studio solutions were found. *Cancel*"); return; } // Prompt user to select solution. PromptKeywordOptions pko = new PromptKeywordOptions("\nSelect Visual Studio instance to increment:"); pko.AllowNone = false; foreach (string name in solNames) { if (name != "") { pko.Keywords.Add(name); } } if (defaultKeyword == "" || solNames.Contains(defaultKeyword) == false) { int index = 0; while (solNames[index] == "") { index++; } pko.Keywords.Default = solNames[index]; } else { pko.Keywords.Default = defaultKeyword; } PromptResult pr = ed.GetKeywords(pko); if (pr.Status != PromptStatus.OK) { return; } defaultKeyword = pr.StringResult; // Use prompt result to set Visual Studio instance variable. _DTE dte = vsInstances.ElementAt(solNames.IndexOf(pr.StringResult)).Value; // Use custom WaitCursor class for long operation. using (WaitCursor wc = new WaitCursor()) { // Active Visual Studio Document. EnvDTE.Document vsDoc = dte.ActiveDocument; if (vsDoc == null) { ed.WriteMessage(String.Format("\nNo active document found for the '{0}' solution. *Cancel*", pr.StringResult)); return; } // Active Visual Studio Project. Project prj = vsDoc.ProjectItem.ContainingProject; // Debug directory - i.e. \bin\Debug. string debugDir = prj.FullName; debugDir = Path.GetDirectoryName(debugDir); debugDir = Path.Combine(debugDir, @"bin\Debug"); // NetReload directory - i.e. \bin\Debug\NetReload. string netReloadDir = Path.Combine(debugDir, "NetReload"); // Create NetReload directory if it doens't exist. if (Directory.Exists(netReloadDir) == false) { Directory.CreateDirectory(netReloadDir); } // Temporary random assembly file name (check it doesn't already exist). string tempAssemblyName; do { tempAssemblyName = Path.GetRandomFileName(); } while (File.Exists(Path.Combine(netReloadDir, tempAssemblyName + ".dll"))); // Project's initial "AssemblyName" property setting. string initAssemblyName = prj.Properties.Item("AssemblyName").Value as string; // Set project's "AssemblyName" property to temp value. prj.Properties.Item("AssemblyName").Value = tempAssemblyName; // Build solution. SolutionBuild solBuild = dte.Solution.SolutionBuild; solBuild.Build(true); // Re-set project's "AssemblyName" property back to initial value. prj.Properties.Item("AssemblyName").Value = initAssemblyName; // Check if build was successful. // # Note: LastBuildInfo property reports number of projects in the solution that failed to build. if (solBuild.LastBuildInfo != 0) { ed.WriteMessage(String.Format("\nBuild failed for the '{0}' solution. *Cancel*", pr.StringResult)); return; } // Move new assembly (.dll) from Debug directory to NetReload directory. File.Move( Path.Combine(debugDir, tempAssemblyName + ".dll"), Path.Combine(netReloadDir, tempAssemblyName + ".dll") ); // Move new .pdb file from Debug directory to NetReload directory. File.Move( Path.Combine(debugDir, tempAssemblyName + ".pdb"), Path.Combine(netReloadDir, tempAssemblyName + ".pdb") ); // NETLOAD new assembly file. System.Reflection.Assembly.LoadFrom(Path.Combine(netReloadDir, tempAssemblyName + ".dll")); // Output summary. ed.WriteMessage("\nNETRELOAD complete for {0}.dll.", initAssemblyName); } } catch (Autodesk.AutoCAD.Runtime.Exception ex) { // Catch AutoCAD exception. Application.ShowAlertDialog(String.Format("ERROR" + "\nMessage: {0}\nErrorStatus: {1}", ex.Message, ex.ErrorStatus)); } catch (System.Exception ex) { // Catch Windows exception. Application.ShowAlertDialog(String.Format("ERROR" + "\nMessage: {0}", ex.Message)); } }
public static DTE GetDTE(Process process) { string namePattern = $@"!VisualStudio\.DTE\.(\d+\.\d+):{process.Id.ToString()}"; return((DTE)RunningObjectTable.GetRunningObjects(namePattern).FirstOrDefault()); }
public static void LaunchBloggingForm(string[] args, IDisposable splashScreen, bool isFirstInstance) { try { using (ProcessKeepalive.Open()) { UpdateManager.CheckforUpdates(); // If the COM registration is not set up correctly, we won't be able to launch. RunningObjectTable.EnsureComRegistration(); // make sure blogging is configured before we proceed if (EnsureBloggingConfigured(splashScreen)) { WriterCommandLineOptions options = WriterCommandLineOptions.Create(args); // check for a prefs request if (options.IsShowPreferences) { if (splashScreen != null) { splashScreen.Dispose(); } ExecuteShowPreferences(options.PreferencesPage); } // check for an open-post request else if (options.IsOpenPost) { if (splashScreen != null) { splashScreen.Dispose(); } ExecuteOpenPost(); } // check for opening an existing post via the shell file association else if (options.IsPostEditorFile) { ExecutePostEditorFile(options.PostEditorFileName, splashScreen); } // check for recovered posts else if (isFirstInstance && RecoverPosts(splashScreen)) { return; } // launch with an new empty post else { ExecuteNewPost(splashScreen, null); } } } } catch { if (splashScreen != null) { splashScreen.Dispose(); } throw; } }
static DTE?GetDTE(Process process) { var namePattern = $@"!VisualStudio\.DTE\.(\d+\.\d+):{process.Id}"; return((DTE?)RunningObjectTable.GetRunningObjects(namePattern).FirstOrDefault()); }
internal static object GetDTEObject(Process process) { string namePattern = $@"!VisualStudio\.DTE\.(\d+\.\d+):{process.Id.ToString()}"; return(RunningObjectTable.GetRunningObjects(namePattern).FirstOrDefault()); }