Click here to Skip to main content
16,016,537 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi I want to block or sleep one of the windows process at its start time.I have the name of this process,Is any way for me to do this work by C#?
Posted
Comments
[no name] 23-Sep-12 5:06am    
Unless you have control of the application's code, you are not going to be able to "sleep" a process. You can command the process to cease running.

1 solution

There is no real way to 'sleep' another process, but you can get close.

The following example will kill the process, if you store the name somewhere in your application you could manually restart it when you want it to 'awake' again.
C#
try
{
    Process proc = Process.GetProcessesByName("explorer");
    proc.Kill();
}
catch (Exception ex)
{
    ex = null;
}


Another way to go is to just lower it's priority to Idle, this will make it consume minimal CPU time, just as if it was asleep, but it will still technically be awake.
C#
try
{
    Process proc = Process.GetProcessesByName("explorer");
    proc.PriorityClass = ProcessPriorityClass.Idle;
}
catch (Exception ex)
{
    ex = null;
}


You can find more details on the Process class here:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process(v=vs.100).aspx[^]

Hope this helped.
 
Share this answer
 
Comments
mr_asadi 23-Sep-12 7:00am    
thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900