public static void ChapterMain() { ThreadPriorityLevel priority = (ThreadPriorityLevel)Enum.Parse( typeof(ThreadPriorityLevel), "Idle"); Console.WriteLine(priority); }
/// <summary> /// Sets the thread's base priority. /// </summary> /// <param name="basePriority">The base priority of the thread.</param> public void SetBasePriorityWin32(ThreadPriorityLevel basePriority) { if (!Win32.SetThreadPriority(this, (int)basePriority)) { Win32.Throw(); } }
public static void TestStart() { var datetime = new DateTime(); // GetType: Gets the System.Type of the current instance. // current instance 说明只能再实例上使用. var type = datetime.GetType(); foreach (var property in type.GetProperties()) { Console.WriteLine(property.Name); } // 使用typeof()创建System.Type实例 ThreadPriorityLevel priority = (ThreadPriorityLevel)Enum.Parse( typeof(ThreadPriorityLevel), "Idle" ); foreach (var item in Enum.GetNames(typeof(ThreadPriorityLevel))) { Console.WriteLine(item); } Console.WriteLine($"(int)ThreadPriorityLevel.Idle is {(int)ThreadPriorityLevel.Idle}"); Console.WriteLine($"ThreadPriorityLevel.Idle is {priority}"); Console.WriteLine($"ThreadPriorityLevel.Idle.ToString is {priority.ToString()}"); }
public void TestPriorityLevelProperty() { CreateDefaultProcess(); ProcessThread thread = _process.Threads[0]; if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { Assert.Throws <PlatformNotSupportedException>(() => thread.PriorityLevel); Assert.Throws <PlatformNotSupportedException>(() => thread.PriorityLevel = ThreadPriorityLevel.AboveNormal); return; } ThreadPriorityLevel originalPriority = thread.PriorityLevel; if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { Assert.Throws <PlatformNotSupportedException>(() => thread.PriorityLevel = ThreadPriorityLevel.AboveNormal); return; } try { thread.PriorityLevel = ThreadPriorityLevel.AboveNormal; Assert.Equal(ThreadPriorityLevel.AboveNormal, thread.PriorityLevel); } finally { thread.PriorityLevel = originalPriority; Assert.Equal(originalPriority, thread.PriorityLevel); } }
public ThreadSync(int core = 0, ThreadPriorityLevel priority = ThreadPriorityLevel.Normal) : base(core, priority) { lock (_syncs) { _syncs.Add(_thread, this); } }
protected SingleThreadWorker(int core, ThreadPriorityLevel priority) { _Core = core; _Priority = priority; _thread = new Thread(_Run); _thread.IsBackground = true; _thread.Start(); }
protected SingleThreadWorker() { _Core = CoreBinder.Allocate(); _Priority = ThreadPriorityLevel.Normal; _thread = new Thread(_Run); _thread.IsBackground = true; _thread.Start(); }
public static void SetThreadPriority(ThreadPriorityLevel priority) { foreach (ProcessThread pt in Process.GetCurrentProcess().Threads) { int utid = GetCurrentThreadId(); if (utid == pt.Id) { pt.PriorityLevel = priority; pt.PriorityBoostEnabled = true; } } }
public static void Bind(int core, ThreadPriorityLevel priority = ThreadPriorityLevel.Normal) { if (core <= 0 || core > 64) { // That isn't gonna work. throw new Exception("Core must be between 1 and 64 inclusive"); } IntPtr core_bitmask = new IntPtr(1 << (core - 1)); Thread.BeginThreadAffinity(); _CurrentThread.ProcessorAffinity = core_bitmask; _CurrentThread.PriorityLevel = priority; }
public static void SetThreadPriority(uint id, ThreadPriorityLevel priorityLevel) { var process = Process.GetCurrentProcess(); var thread = process.Threads .Cast <ProcessThread>() .FirstOrDefault(t => t.Id == id); if (thread == null) { throw new ArgumentOutOfRangeException(); } thread.PriorityLevel = priorityLevel; }
public void TestPriorityLevelProperty_Unix() { CreateDefaultProcess(); ProcessThread thread = _process.Threads[0]; ThreadPriorityLevel level = ThreadPriorityLevel.Normal; if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { Assert.Throws <PlatformNotSupportedException>(() => thread.PriorityLevel); } else { level = thread.PriorityLevel; } Assert.Throws <PlatformNotSupportedException>(() => thread.PriorityLevel = level); }
public void TestPriorityLevelProperty_Unix() { CreateDefaultProcess(); ProcessThread thread = _process.Threads[0]; ThreadPriorityLevel level = ThreadPriorityLevel.Normal; if (OperatingSystem.IsMacOS()) { Assert.Throws <PlatformNotSupportedException>(() => thread.PriorityLevel); } else { level = thread.PriorityLevel; } Assert.Throws <PlatformNotSupportedException>(() => thread.PriorityLevel = level); }
/// <summary> /// Returns the priority level based on the priority level passed and the increase indicator /// </summary> /// <param name="current">Reference Priority level of that needs to be increased or decreased</param> /// <param name="increase">Indicator to increase or decrease the priority level</param> /// <returns>Changed priority level</returns> private static ThreadPriorityLevel GetPriority(ThreadPriorityLevel current, bool increase) { if (increase) { switch (current) { case ThreadPriorityLevel.AboveNormal: return(ThreadPriorityLevel.Highest); case ThreadPriorityLevel.BelowNormal: return(ThreadPriorityLevel.Normal); case ThreadPriorityLevel.Idle: return(ThreadPriorityLevel.Lowest); case ThreadPriorityLevel.Lowest: return(ThreadPriorityLevel.BelowNormal); case ThreadPriorityLevel.Normal: return(ThreadPriorityLevel.AboveNormal); } } else { switch (current) { case ThreadPriorityLevel.AboveNormal: return(ThreadPriorityLevel.Normal); case ThreadPriorityLevel.BelowNormal: return(ThreadPriorityLevel.Lowest); case ThreadPriorityLevel.Highest: return(ThreadPriorityLevel.AboveNormal); case ThreadPriorityLevel.Lowest: return(ThreadPriorityLevel.Idle); case ThreadPriorityLevel.Normal: return(ThreadPriorityLevel.BelowNormal); } } return(current); }
public void OnCreateProcess(Int32 InClientPID, Int32[] pIds,int oldThrId,ThreadPriorityLevel oldThrLvl ,string ChannelName) { for (int i = 0; i < pIds.Length; i++) { try { RemoteHooking.Inject(pIds[i], "InjectDLL.dll", "InjectDLL.dll", ChannelName); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } Process pro = Process.GetProcessById(pIds[i]); foreach (ProcessThread thread in pro.Threads) { if(thread.Id == oldThrId) thread.PriorityLevel = oldThrLvl; } } }
private void SetThreadPriority(ThreadPriorityLevel priority) { try { int tid = int.Parse(listThreads.SelectedItems[0].SubItems[0].Text); using (var thandle = new ThreadHandle(tid, OSVersion.MinThreadSetInfoAccess)) thandle.SetBasePriorityWin32(priority); } catch (Exception ex) { PhUtils.ShowException("Unable to set the priority of the thread", ex); } }
/// <summary> /// Loads settings from an xml document /// </summary> /// <returns>The options</returns> /// <exception cref="OptionsException">Any problems during loading</exception> public static ProgramOptions LoadSettings() { ProgramOptions options = new ProgramOptions(); try { if (File.Exists(Files.ProfileFile)) { XmlDocument document = new XmlDocument(); document.Load(Files.ProfileFile); options.AmountOf7ZipProcessesToProcessSynchronously = readNode(document, "/Settings/Core/Performance/AmountOf7ZipProcessesToProcessSynchronously", Constants.AmountOf7ZipProcessesToProcessSynchronouslyMinimum, Constants.AmountOf7ZipProcessesToProcessSynchronouslyMaximum, Constants.AmountOf7ZipProcessesToProcessSynchronouslyDefault); options.AmountOfStoragesToProcessSynchronously = readNode(document, "/Settings/Core/Performance/AmountOfStoragesToProcessSynchronously", Constants.AmountOfStoragesToProcessSynchronouslyMinimum, Constants.AmountOfStoragesToProcessSynchronouslyMaximum, Constants.AmountOfStoragesToProcessSynchronouslyDefault); string priority = readNode(document, "/Settings/Core/Performance/ProcessingPriority", ThreadPriority.BelowNormal.ToString()); options.Priority = (ThreadPriority)ThreadPriorityLevel.Parse(typeof(ThreadPriority), priority); options.DontCareAboutPasswordLength = readNode(document, "/Settings/Core/Security/DontCareAboutPasswordLength", false); string logLevel = readNode(document, "/Settings/Core/Logging/Level", LogLevel.Normal.ToString()); options.LoggingLevel = (LogLevel)ThreadPriorityLevel.Parse(typeof(LogLevel), logLevel); options.LogsFolder = readNode(document, "/Settings/Core/Logging/Location", Directories.LogsFolder); options.ShowSchedulerInTray = readNode(document, "/Settings/Core/ScheduleApplication/ShowInTray", true); options.PuttingOffBackupCpuLoading = (byte)readNode(document, "/Settings/Core/ScheduleApplication/PuttingOffBackupCpuLoading", Constants.MinimumCpuLoading, Constants.MaximumCpuLoading, Constants.DefaultCpuLoading); options.DontNeedScheduler = readNode(document, "/Settings/Core/ScheduleApplication/" + _DONT_NEED_SCHEDULER_TAG, false); options.HaveNoNetworkAndInternet = readNode(document, "/Settings/Core/" + _CONFIGURATOR_TAG + "/" + _HAVE_NO_INTERNET_AND_NETWORK_TAG, false); options.DontCareAboutSchedulerStartup = readNode(document, "/Settings/Core/" + _CONFIGURATOR_TAG + "/" + _DONT_CARE_ABOUT_SCHEDULER_STARTUP_TAG, false); options.HideAboutTab = readNode(document, "/Settings/Core/" + _CONFIGURATOR_TAG + "/" + _HIDE_ABOUT_TAB_TAG, false); XmlNodeList taskNodes = document.SelectNodes("/Settings/BackupTasks/Task"); foreach (XmlNode taskNode in taskNodes) { BackupTask task = new BackupTask(); task.Name = taskNode.Attributes[_NAME].Value; task.SecretPassword = taskNode[_PASSWORD].InnerText; XmlNodeList compressionItemsNodes = taskNode[_WHAT_TAG].ChildNodes; XmlNodeList storagesNodes = taskNode[_WHERE_TAG].ChildNodes; XmlNodeList beforeNodes = taskNode[_CHAIN_OF_PROGRAMS_TO_RUN][_BEFORE_BACKUP].ChildNodes; XmlNodeList afterNodes = taskNode[_CHAIN_OF_PROGRAMS_TO_RUN][_AFTER_BACKUP].ChildNodes; foreach (XmlNode nodeItem in beforeNodes) { BackupEventTaskInfo info = new BackupEventTaskInfo( nodeItem.Attributes[_NAME].Value, nodeItem.Attributes[_ARGUMENTS].Value); task.BeforeBackupTasksChain.Add(info); } foreach (XmlNode nodeItem in afterNodes) { BackupEventTaskInfo info = new BackupEventTaskInfo( nodeItem.Attributes[_NAME].Value, nodeItem.Attributes[_ARGUMENTS].Value); task.AfterBackupTasksChain.Add(info); } foreach (XmlNode compressionItemNode in compressionItemsNodes) { CompressionItem item = new CompressionItem( compressionItemNode.Attributes[_TARGET_TAG].Value, bool.Parse(compressionItemNode.Attributes[_IS_FOLDER].Value), (CompressionDegree)CompressionDegree.Parse(typeof(CompressionDegree), compressionItemNode.Attributes[_COMPRESSION_DEGREE_TAG].Value)); task.FilesFoldersList.Add(item); } XmlNode schedule = taskNode[_SCHEDULE_TAG]; XmlNode zeroHour = schedule[_TIME_TAG]; XmlNode days = schedule[_DAYS_TAG]; task.Hours = byte.Parse(zeroHour.Attributes[_HOUR_TAG].Value); task.Minutes = byte.Parse(zeroHour.Attributes[_MINUTE_TAG].Value); foreach (DayOfWeek enumItem in DayOfWeek.GetValues(typeof(DayOfWeek))) { task.SetSchedulingStateOfDay(enumItem, bool.Parse(days.Attributes[enumItem.ToString()].Value)); } foreach (XmlNode storageNode in storagesNodes) { Dictionary <string, string> settings = new Dictionary <string, string>(); foreach (XmlNode node in storageNode.ChildNodes) { settings.Add(node.Name, node.InnerText); } XmlAttribute assemblyAttribute = storageNode.Attributes[_ASSEMBLY_TAG]; // this is done to prevent using different assemblies of a different copies of a program Assembly assembly = (assemblyAttribute != null) ? Assembly.LoadFrom(assemblyAttribute.Value) : Assembly.GetExecutingAssembly(); string type = storageNode.Attributes[_TYPE_TAG].Value; StorageBase storage = (StorageBase)Activator.CreateInstance(assembly.GetType(type), settings); task.Storages.Add(storage); } options.BackupTasks.Add(task.Name, task); } } } catch (Exception exc) { Debug.WriteLine(exc.ToString()); throw new OptionsException( string.Format(CultureInfo.CurrentCulture, _fileInaccessibleOrCorrupted, Files.ProfileFile, exc.Message)); } return(options); }
static extern bool SetThreadPriority(IntPtr hThread, ThreadPriorityLevel nPriority);
public bool SetPriority(ThreadPriorityLevel level) => NativeMethods.SetThreadPriority(new IntPtr((long)Handle), level);
public void OnCreateProcess(Int32 InClientPID, Int32[] pIds, int oldThrId, ThreadPriorityLevel oldThrLvl,string ApplicationName,string CommandLine,int CreationFlags,string ChannelName) { //string InLibraryPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(typeof(FileMonInterface).Assembly.Location), "InjectDLL.dll"); //int ProcessId = 0; //RemoteHooking.CreateAndInject(ApplicationName, CommandLine, CreationFlags, InLibraryPath, InLibraryPath, out ProcessId, ChannelName); //for (int i = 0; i < pIds.Length; i++) //{ // bool first = true; // if (!Global.hookProcessed.Contains(pIds[i])) // { // while (true) // { // try // { // if (first) // { // Process pro = Process.GetProcessById(pIds[i]); // RemoteHooking.Inject(pIds[i], // "InjectDLL.dll", // "InjectDLL.dll", // ChannelName); // Global.hookProcessed.Add(pIds[i]); // foreach (ProcessThread thread in pro.Threads) // { // if (thread.Id == oldThrId) // thread.PriorityLevel = oldThrLvl; // } // } // else // { // int Processid = 0; // //RemoteHooking.CreateAndInject(ApplicationName, CommandLine, CreationFlags, "InjectDLL.dll", "InjectDLL.dll",out Processid, ChannelName); // Console.WriteLine(CommandLine); // ProcessStartInfo startInfo = new ProcessStartInfo(ApplicationName, CommandLine); // Process pro = Process.Start(startInfo); // first = true; // List<ThreadPriorityLevel> oldLvl = new List<ThreadPriorityLevel>(); // foreach (ProcessThread thread in pro.Threads) // { // oldLvl.Add(thread.PriorityLevel); // thread.PriorityLevel = ThreadPriorityLevel.Idle; // } // RemoteHooking.Inject(pro.Id, // "InjectDLL.dll", // "InjectDLL.dll", // ChannelName); // int cnt = 0; // foreach (ProcessThread thread in pro.Threads) // { // thread.PriorityLevel = oldLvl[cnt++]; // } // } // break; // } // catch (Exception ex) // { // Console.WriteLine(ex); // first = false; // continue; // } // } // } //} }
public static extern bool SetThreadPriority(IntPtr hThread, ThreadPriorityLevel level);
public GThread(ThreadParameter param, ThreadPriorityLevel priorityLevel) : this(priorityLevel) { _threadParameter = param; }
public GThread(ThreadPriorityLevel priorityLevel) : this() { _startPriorityLevel = priorityLevel; }
public static void SetPriorityProcessAndThreads(string nameProcess, ProcessPriorityClass processPriority, ThreadPriorityLevel threadPriorityLevel) { foreach (var a in Process.GetProcessesByName(nameProcess)) { a.PriorityBoostEnabled = true; a.PriorityClass = processPriority; foreach (ProcessThread processThread in a.Threads) { processThread.PriorityLevel = threadPriorityLevel; processThread.PriorityBoostEnabled = true; } } }
static extern bool SetThreadPriority(IntPtr hThread, ThreadPriorityLevel nPriority);
public void SetPriority(ThreadPriorityLevel priority) { Thread.SetPriority(priority); RaisePropertyChanged(nameof(Priority)); }