Click here to Skip to main content
Sign Up to vote bad
good
See more: C#
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 22 Sep '12 - 23:03

Comments
Wes Aday - 23 Sep '12 - 5:06
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.
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.
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.
  Permalink  
Comments
mr_asadi - 23 Sep '12 - 7:00
thank you.

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 449
1 Mahesh Bailwal 373
2 Maciej Los 255
3 CPallini 175
4 Rohan Leuva 175
0 Sergey Alexandrovich Kryukov 9,402
1 OriginalGriff 7,204
2 CPallini 3,933
3 Rohan Leuva 3,211
4 Maciej Los 2,743


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 23 Sep 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid