Skip to content

Gendarme.Rules.Ui.UseSTAThreadAttributeOnSWFEntryPointsRule(2.10)

Sebastien Pouliot edited this page Feb 9, 2011 · 3 revisions

UseSTAThreadAttributeOnSWFEntryPointsRule

Assembly: Gendarme.Rules.Ui
Version: 2.10

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 ()
    {
    }
}
Clone this wiki locally