private void EnumProcesses() { _processList.Clear(); foreach (var currentProc in from proc in Process.GetProcesses() orderby proc.ProcessName select proc) { try { // This can sometimes happen between calling GetProcesses and getting here. Save ourselves the throw. if (currentProc.HasExited) { continue; } _processList.Add(new ProcessInfo { FileName = currentProc.ProcessName, Id = currentProc.Id, Owner = RemoteHooking.GetProcessIdentity(currentProc.Id).Name }); } catch (AccessViolationException) { // noop, there's a lot of system processes we can't see. } catch (Win32Exception) { // noop, there's a lot of system processes we can't see. } catch (Exception aEx) { _log.Error(aEx); } } }
private void EnumProcesses() { Dispatcher.Invoke(() => { _processList.Clear(); }); Dispatcher.Invoke(() => { ProcessStatus = "Scanning Processes..."; }); var cp = Process.GetCurrentProcess().Id; const ProcessAccessRights flags = ProcessAccessRights.PROCESS_QUERY_INFORMATION | ProcessAccessRights.PROCESS_VM_READ; var procList = from proc in Process.GetProcesses() orderby proc.ProcessName select proc; Parallel.ForEach(procList, (currentProc) => { if (_scanningToken.IsCancellationRequested) { return; } var handle = IntPtr.Zero; try { // This can sometimes happen between calling GetProcesses and getting here. Save ourselves the throw. if (currentProc.HasExited || currentProc.Id == cp) { return; } // This is usually what throws, so do it before we invoke via dispatcher. var owner = RemoteHooking.GetProcessIdentity(currentProc.Id).Name; if ((handle = Native.OpenProcess(flags, false, currentProc.Id)) == IntPtr.Zero) { return; } var procInfo = new ProcessInfo { FileName = currentProc.ProcessName, Id = currentProc.Id, }; if (XInputMod.CanUseMod(handle)) { procInfo.Owner = owner; } if (UnityVRMod.CanUseMod(handle, currentProc.MainModule.FileName, out var module, out var frameworkVersion)) { procInfo.MonoModule = module; procInfo.FrameworkVersion = frameworkVersion; } if (procInfo.CanUseXInput || procInfo.CanUseMono) { Dispatcher.Invoke(() => { _log.Debug(procInfo); _processList.Add(procInfo); }); } }
private void EnumProcesses() { Dispatcher.Invoke(() => { _processList.Clear(); }); Dispatcher.Invoke(() => { ProcessError = "Scanning Processes..."; }); var cp = Process.GetCurrentProcess().Id; const ProcessAccessRights flags = ProcessAccessRights.PROCESS_QUERY_INFORMATION | ProcessAccessRights.PROCESS_VM_READ; foreach (var currentProc in from proc in Process.GetProcesses() orderby proc.ProcessName select proc) { var handle = IntPtr.Zero; try { // This can sometimes happen between calling GetProcesses and getting here. Save ourselves the throw. if (currentProc.HasExited || currentProc.Id == cp) { continue; } // This is usually what throws, so do it before we invoke via dispatcher. var owner = RemoteHooking.GetProcessIdentity(currentProc.Id).Name; if ((handle = Native.OpenProcess(flags, false, currentProc.Id)) == IntPtr.Zero) { continue; } var procInfo = new ProcessInfo { FileName = currentProc.ProcessName, Id = currentProc.Id, }; if (XInputMod.CanUseMod(handle)) { procInfo.Owner = owner; } if (UnityVRMod.CanUseMod(handle, currentProc.MainModule.FileName, out var module, out var frameworkVersion)) { procInfo.MonoModule = module; procInfo.FrameworkVersion = frameworkVersion; } if (procInfo.CanUseXInput || procInfo.CanUseMono) { Dispatcher.Invoke(() => { _log.Debug(procInfo); _processList.Add(procInfo); }); } } catch (AccessViolationException) { // noop, there's a lot of system processes we can't see. } catch (Win32Exception) { // noop, there's a lot of system processes we can't see. } catch (Exception aEx) { _log.Error(aEx); } finally { // Only close the if (handle != IntPtr.Zero) { Native.CloseHandle(handle); } } } Dispatcher.Invoke(() => { ProcessError = "Select Process to Inject"; }); _enumProcessTask = null; }
/// <summary> /// 加载缓存 zhangdahang 2013-11-15 /// 算法思路: /// 1、从服务器获得需要更新的表(表名,版本)列表 /// 2、对比本地对应表的版本,决定是否需要更新 /// 3、对需要更新的表,获取其表中的所有记录(ID,版本)列表 /// 4、对比本地其表中的记录和版本,统计需要更新的记录集 /// 5、对需要更新的记录集中的记录进行更新,如有需要,分批更新。 /// </summary> /// <param name="status"></param> public static void LoadCache_Update(object status) { //修复Bug307 #region 准备 float step = 1; String Msg = "系统正在更新..."; IProgressCallback callBack = status as IProgressCallback; if (Yqun.Common.ContextCache.ApplicationContext.Current.ISLocalService) { if (callBack != null) { callBack.End(); } return; } DataTable ServerDataCache = null; DataTable LocalDataCache = null; //栓查版本列,如没有版本列,添加“Stcs_1”列,目前以时间作为记录版本 CompareField(); #endregion callBack.SetText(Msg); callBack.Begin(0, 100); Thread.Sleep(500); //获取服务器表集, try { ServerDataCache = GetServerDataCache(); LocalDataCache = GetLocalDataCache(); } catch (Exception ex) { Msg = string.Format("更新缓存失败,原因:“{0}”,请及时联系管理员!", ex.Message); logger.Error(Msg); if (callBack != null) { callBack.End(); } return; } step = ProgressGo(callBack, step); DataTable updateTable = GetUpdateDateTable(ServerDataCache, LocalDataCache); if (updateTable.Rows.Count == 0) { if (callBack != null) { callBack.End(); } return; } logger.Error("共有" + updateTable.Rows.Count + "表需要更新"); DataSet UpdateDB = new DataSet(); foreach (DataRow cacheRow in updateTable.Rows) { string tableName = cacheRow["tableName"].ToString(); callBack.SetText("分析表:" + tableName + "需要更新的记录"); DataTable ServerTable = GetServerDataTalbe("select ID,Scts_1 from " + tableName); if (LocalDataCache.Select("tableName ='" + tableName + "'").Length == 0) { DataRow newCacheRow = LocalDataCache.NewRow(); newCacheRow.ItemArray = cacheRow.ItemArray; LocalDataCache.Rows.Add(newCacheRow); callBack.SetText("添加新表:" + tableName); UpdateTableData(LocalDataCache.TableName, LocalDataCache); } DataTable LocalTable = GetLocalDataTable("select ID,Scts_1 from " + tableName); DataTable updateRecordTable = GetUpdateDateTable(ServerTable, LocalTable); lock (ProcessInfoList) { if (!ProcessInfoList.ContainsKey(tableName.ToLower().Trim())) { ProcessInfo pi = new ProcessInfo(); pi.CompletedRowsCount = 0; pi.TableRowsCount = updateRecordTable.Rows.Count; ProcessInfoList.Add(tableName.ToLower().Trim(), pi); } } UpdateDB.Tables.Add(updateRecordTable); } //更新 foreach (DataTable table in UpdateDB.Tables) { string tableName = table.TableName; #region 可以更新 if (table.Rows.Count == 0) { DataTable cacheTalbe = GetServerDataTalbe("select * from sys_biz_Cache where tableName='" + tableName + "'"); UpdateTableData("sys_biz_Cache", cacheTalbe); continue; } #endregion callBack.SetText("开始更新,表:" + tableName); string IDStr = ""; int index = 0; Int32 pageSize = GetPageSize(tableName); for (; index < table.Rows.Count; index++) { IDStr += "'" + table.Rows[index]["ID"].ToString() + "',"; if ((index != 0 && index % pageSize == 0) || index == table.Rows.Count - 1) { try { IDStr = IDStr.Substring(IDStr.Length - 1) == "," ? IDStr.Remove(IDStr.Length - 1) : IDStr; string sqlStr = "select * from " + tableName + " where ID in (" + IDStr + ")"; IDStr = ""; object[] parameterArr = new object[] { tableName, sqlStr, callBack, table, ServerDataCache }; //启动一个线程 ,更新本地数据据 System.Threading.Thread process = GetOneThread(); process.Start(parameterArr); } catch (Exception e) { logger.Error(e.ToString()); } } } } bool HasRunningThread = true; while (HasRunningThread) { HasRunningThread = false; lock (RunningThreads) { foreach (Thread t in RunningThreads) { if (t.ThreadState == ThreadState.Running) { HasRunningThread = true; break; } } } Thread.Sleep(50); } logger.Error("更新完成"); callBack.SetText("更新成功!"); callBack.StepTo(100); Thread.Sleep(1000); if (callBack != null) { callBack.End(); } }