rspec/rules/S4210/vbnet/rule.adoc

30 lines
853 B
Plaintext
Raw Normal View History

2020-06-30 12:49:37 +02:00
When an assembly uses Windows Forms (classes and interfaces from the <code>System.Windows.Forms</code> namespace) its entry point should be marked with the <code>STAThreadAttribute</code> to indicate that the threading model should be "Single-Threaded Apartment" (STA) which is the only one supported by Windows Forms.
This rule raises an issue when the entry point (<code>Shared Sub Main</code> method) of an assembly using Windows Forms is not marked as STA.
== Noncompliant Code Example
----
Imports System.Windows.Forms
Public Class Foo
Shared Sub Main()
Dim winForm As Form = New Form
Application.Run(winForm)
End Sub
End Class
----
== Compliant Solution
----
Imports System.Windows.Forms
Public Class Foo
<STAThread()> Shared Sub Main()
Dim winForm As Form = New Form
Application.Run(winForm)
End Sub
End Class
----