title: Kill Specified Task instead of Process in C#
body: <p>Like Microsoft Word, If we open multiple Word windows, then we will find that they are under one process named WINWORD with multiple tasks under it. </p>
  
  <p>In task manager of Window 8.1 Pro, we can right click it and end it by End Task.</p>
  
  <p>I success to do the end process with process name but I cannot get any idea from Google search that how to do the kill certain task under certain process in this situation.</p>
  
  <p>Emphasize: I am not asking how to kill the <strong>process</strong>.</p>
  
  <p><strike>processes[i].Kill();</strike></p>
  
  <h2>Update</h2>
  
  <p>I success to kill the specified Word Window with</p>
  
  <pre><code>using System;
  using System.Runtime.InteropServices;
  
  namespace CloseTask
  {
      class Program
      {
          [DllImport("user32.dll")]
          public static extern int FindWindow(string lpClassName,string lpWindowName);
          [DllImport("user32.dll")]
          public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);
  
          public const int WM_SYSCOMMAND = 0x0112;
          public const int SC_CLOSE = 0xF060;
  
          static void Main(string[] args)
          {
              closeWindow();
          }
  
          private static void closeWindow()
          {
              // retrieve the handler of the window of Word
              // Class name, Window Name
              int iHandle = FindWindow("OpusApp", "Document1 - Microsoft Word");
              if (iHandle &gt; 0)
              {
                  //close the window using API
                  SendMessage(iHandle, WM_SYSCOMMAND, SC_CLOSE, 0);
              }
          }   
      }
  }
  </code></pre>
  
  <p>But I wonder how can I kill the <strong>oldest</strong> Word Window in this case? If process can sort the StartTime to kill the oldest one.... But I think this should be included in another question, thanks.</p>