Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

70 lines
1.4 KiB
Plaintext

== Why is this an issue?
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.
This rule raises an issue when the entry point (``++static void Main++`` method) of an assembly using Windows Forms is not marked as STA.
=== Noncompliant code example
[source,csharp]
----
using System;
using System.Windows.Forms;
namespace MyLibrary
{
public class MyForm: Form
{
public MyForm()
{
this.Text = "Hello World!";
}
public static void Main() // Noncompliant
{
var form = new MyForm();
Application.Run(form);
}
}
}
----
=== Compliant solution
[source,csharp]
----
using System;
using System.Windows.Forms;
namespace MyLibrary
{
public class MyForm: Form
{
public MyForm()
{
this.Text = "Hello World!";
}
[STAThread]
public static void Main()
{
var form = new MyForm();
Application.Run(form);
}
}
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
endif::env-github,rspecator-view[]