rspec/rules/S4210/vbnet/rule.adoc

44 lines
1.0 KiB
Plaintext
Raw Permalink Normal View History

== Why is this an issue?
2021-01-27 13:42:22 +01:00
When an assembly uses Windows Forms (classes and interfaces from the ``++System.Windows.Forms++`` namespace) its entry point should be marked with the ``++STAThreadAttribute++`` to indicate that the threading model should be "Single-Threaded Apartment" (STA) which is the only one supported by Windows Forms.
2020-06-30 12:49:37 +02:00
2021-02-02 15:02:10 +01:00
2021-01-27 13:42:22 +01:00
This rule raises an issue when the entry point (``++Shared Sub Main++`` method) of an assembly using Windows Forms is not marked as STA.
2020-06-30 12:49:37 +02:00
=== Noncompliant code example
2020-06-30 12:49:37 +02:00
2022-02-04 17:28:24 +01:00
[source,vbnet]
2020-06-30 12:49:37 +02:00
----
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
2020-06-30 12:49:37 +02:00
2022-02-04 17:28:24 +01:00
[source,vbnet]
2020-06-30 12:49:37 +02:00
----
Imports System.Windows.Forms
Public Class Foo
<STAThread()> Shared Sub Main()
Dim winForm As Form = New Form
Application.Run(winForm)
End Sub
End Class
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
endif::env-github,rspecator-view[]