An alternative to the mess of writing FxCop rules is to use the NDepend tool. This tool allows you to write code rules over LINQ C # queries , what we call CQLinq . Disclaimer: I am one of the developers of this tool
By default, more than 200 code rules are suggested. Configuring existing rules or creating your own rules directly because of the well-known C # LINQ syntax.
How to write a code analysis tool for vs2008 to prevent a specific infrastructure call, for example, GC.WaitForFullGCComplete () or Application.DoEvents ()
For this specific need, the simple following CQLinq rule is sufficient (note the use of AllowNoMatch () to make this rule work in any situation):
// <Name>Don't call these methods</Name> warnif count > 0 from m in Methods where m.IsUsing ("System.GC.WaitForFullGCComplete()".AllowNoMatch()) || m.IsUsing ("System.GC.WaitForFullGCComplete(Int32)".AllowNoMatch()) || m.IsUsing ("System.Windows.Forms.Application.DoEvents()".AllowNoMatch()) select m
CQLinq queries can be edited in real time in VisualStudio and offer instant results with the ability to view results:

More precisely, the rules can be checked live in Visual Studio and during the build process, the generated HTML + javascript report .
Patrick from NDepend team
source share