xxxxプログラマのメモ

先人に感謝と敬意:自分の困ったこと調べたことのメモ

Task.Factory.StartNew not executing the task when deployed

stackoverflow.com

Sometimes this kind of behaviour is an indication of an overloaded ThreadPool.

Seeing as these are long running/blocking tasks, they should not be scheduled to run in the ThreadPool, which is where Task.Factory.StartNew will be sending them using the default TaskScheduler.

IMO, Task.Factory.StartNew is probably not best suited to this, and you'd be better off spinning up your own threads to run these loops.

ThreadStart action=()=>{
    //do your thing
};
Thread thread=new Thread(action){IsBackground=true};
thread.Start();

Thanks!

pass array of an object to webapi #Get #FromUri #配列 #List

stackoverflow.com

ObjectListを[FromUri]引数にしたけど、おとなしく[FromBody]にしておきます。

http://localhost:3610/api/phonenumber/getphonenumbersbynumbers?
    id[0][PhoneNumber]=8016667777&id[0][FinDate]=2012-02-11&id[0][State]=UT&
    id[1][PhoneNumber]=8018889999&id[1][RfiDate]=2012-12-01&id[1][State]=UT

Get Process Owner from process name/id #Process #user #owner

stackoverflow.com

public string GetProcessOwner(string processName)
{
    string query = "Select * from Win32_Process Where Name = \"" + processName + "\"";
    ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
    ManagementObjectCollection processList = searcher.Get();

    foreach (ManagementObject obj in processList)
    {
        string[] argList = new string[] { string.Empty, string.Empty };
        int returnVal = Convert.ToInt32(obj.InvokeMethod("GetOwner", argList));
        if (returnVal == 0)
        {
            // return DOMAIN\user
            string owner = argList[1] + "\\" + argList[0];
            return owner;       
        }
    }

    return "NO OWNER";
}

Thanks!