Aug 31
Setting process priority
Posted by Wei in C# on 08 31st, 2011| | No Comments »

If you are developing something that requires use of 3rd party programs, it usually is a good idea to change the priority of the process to something below normal otherwise it may take up all server resources which could result in performance issues to other users.

The process priority can only be set through System.Diagnostics.Process:

System.Diagnostics.Process myProcess = null;
myProcess = System.Diagnostics.Process.Start(@"C:\\path\\to\\some\\program", "-param1 value1 -param2 value2...");
myProcess.PriorityClass = System.Diagnostics.ProcessPriorityClass.BelowNormal;

However, if the process that is being started is an assembly such as Microsoft.Office.Interop.Word where you would use Word.Application oWord = new Word.Application(), setting the priority class is a little more difficult.

In my research, I was not able to find an easy way of setting the process to below normal, so I had to settle with a work around.

System.Diagnostics.Process[] thisProc = System.Diagnostics.Process.GetProcessesByName("WINWORD");
foreach (System.Diagnostics.Process proc in thisProc)
{
    proc.PriorityClass = System.Diagnostics.ProcessPriorityClass.BelowNormal;
}

This probably needs to be run with elevated privileges, so the full code would be:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    System.Diagnostics.Process[] thisProc = System.Diagnostics.Process.GetProcessesByName("WINWORD");
    foreach (System.Diagnostics.Process proc in thisProc)
    {
        proc.PriorityClass = System.Diagnostics.ProcessPriorityClass.BelowNormal;
    }
});

Aug 24

Here's a useful post on how to map a SharePoint URL with PictureURL in user profile properties.

http://spmat.blogspot.com/2010/10/how-to-map-sharepoint-2010-pictureurl.html

Here's one to map an extension attribute in AD to the PictureURL in user profile properties.

http://goodbadtechnology.blogspot.com/2010/05/setting-up-pictureurl-user-profile.html

Unfortunately, as you can see from these examples, it's not exactly a straightforward task.