-1

Usually this is done by simply adding [STAThread] on the Main method - However with new projects there is none of that?

When i try to set my own program entry point like this:

class Program
{
    [STAThread]
    static void Main(string[] args)
    {
        var application = new App();
        application.Run();
    }
}

it says that there is more than one program entries found. So yeah - with old .net wpf this worked, how to do it with netcore3/net5+ ?

Dbl
  • 5,634
  • 3
  • 41
  • 66
  • _"with old .net wpf this worked"_ -- not clear what you mean by that. The "old" WPF and the .NET Core version of WPF work exactly the same: the program entry point is generated for you, and if you were to try to explicitly create the entry point yourself, you'd get an error. – Peter Duniho Jul 26 '21 at 22:38

1 Answers1

3

You don't need to - the automatically generated Main method already has that.

You can find the generated files in the appropriate obj directory. For example, I just ran dotnet new wpf from a WpfSta directory and this was generated as part of obj/Debug/net5.0-windows/App.g.cs:

/// <summary>
/// Application Entry Point.
/// </summary>
[System.STAThreadAttribute()]
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "5.0.6.0")]
public static void Main() {
    WpfSta.App app = new WpfSta.App();
    app.InitializeComponent();
    app.Run();
}

You can write your own Main method, and then use the StartupObject property in your project file to specify the entry point. But if it's just for adding STAThread, you don't need to.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194