title: Limiting process memory with MaxWorkingSet
body: <p>MSDN:</p>
  
  <p><code>public IntPtr MaxWorkingSet { get; set; }</code></p>
  
  <blockquote>
    <p>Gets or sets the maximum allowable
    working set size for the associated
    process. Property Value: The maximum
    working set size that is allowed in
    memory for the process, in bytes.</p>
  </blockquote>
  
  <p>So, as far as I understand, I can limit amount of memory that can be used by a process. I've tried this, but with no luck.. </p>
  
  <p>Some code:</p>
  
  <pre><code>public class A
  {
      public void Do()
      {
          List&lt;string&gt; guids = new List&lt;string&gt;();
          do
          {
              guids.Add(Guid.NewGuid().ToString());
              Thread.Sleep(5);
          } while (true);
      }
  }
  
  
  public static class App
  {
      public static void Main()
      {
          Process.GetCurrentProcess().MaxWorkingSet = new IntPtr(2097152);
          try
          {
              new A().Do();
          }
          catch (Exception e)
          {
  
          }
      }
  }
  </code></pre>
  
  <p>I'm expecting OutOfMemory exception after the limit of 2mb is reached, but nothing happens.. If I open Task Manager I can see that the amount of memory my application uses is growing continiously without any limits.</p>
  
  <p>What am I doing wrong?
  Thanks in advance</p>