Skip to content

Gendarme.Rules.Ui.UseSTAThreadAttributeOnSWFEntryPointsRule(git)

Sebastien Pouliot edited this page Mar 2, 2011 · 1 revision

UseSTAThreadAttributeOnSWFEntryPointsRule

Assembly: Gendarme.Rules.Ui
Version: git

Description

This rule checks executable assemblies, i.e. *.exe's, that reference System.Windows.Forms to ensure that their entry point is decorated with [[System.STAThread|http://msdn.microsoft.com/library/System.STAThreadAttribute.aspx]] attribute and is not decorated with [[System.MTAThread|http://msdn.microsoft.com/library/System.MTAThreadAttribute.aspx]] attribute to ensure that Windows Forms work properly.

Examples

Bad example #1 (no attributes):

public class WindowsFormsEntryPoint {
    static void Main ()
    {
    }
}

Bad example #2 (MTAThread)

public class WindowsFormsEntryPoint {
    [MTAThread]
    static void Main ()
    {
    }
}

Good example #1 (STAThread):

public class WindowsFormsEntryPoint {
    [STAThread]
    static void Main ()
    {
    }
}

Good example #2 (not Windows Forms):

public class ConsoleAppEntryPoint {
    static void Main ()
    {
    }
}

Source code

You can browse the latest source code of this rule on github.com

Clone this wiki locally