title: How to detect and avoid infinite loops?
body: <p>I want to make sure that my web application is performance wise and will not make any performance problems. When I searched, I found that one of the most common problems related to the performance issue is the "infinite loops" problem.</p>
  
  <p>I want to ask:</p>
  
  <p>Where should I begin to check that my code never causes infinite loops?</p>
  
  <p>Are there any articles, advices, instructions, examples? I will be grateful.</p>
  
  <p>ex:</p>
  
  <p>May this code cause an infinite loop?</p>
  
  <pre><code>public static IEnumerable&lt;SubjectNode&gt; ReadSubjectNodes(string filePath)
  {
      using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
      using (XmlReader xrdr = new XmlTextReader(fs))
          while (xrdr.Read())
              if (xrdr.NodeType == XmlNodeType.Element &amp;&amp; xrdr.LocalName == "subject")
                  yield return new SubjectNode(xrdr.GetAttribute("id"), xrdr.GetAttribute("name"), xrdr.GetAttribute("short"));
  }
  </code></pre>
  
  <p>Thanks in advance</p>