I’m trying to make a single instance WPF application using the hints on:
What is the correct way to create a single-instance application?
This ultimately requires changes to Main(). In WPF, Main() seems to be auto-generated. I’d rather not modify autogenerated code. Is there a way to suppress Main from being auto-generated?
(alternatively, if you know of a better single app instance pattern for WPF that doesn’t rely on modifying auto-generated code, please suggest it)
From the blog: http://bengribaudo.com/blog/2010/08/26/136/wpf-where-is-your-static-main-method
The following two methods will avoid the duplicate Main collision:
Tell the compiler that your static Main() method should be the execution entry point—Set your project’s “Startup object” setting to the class containing your static Main() method (right-click on the project in Solution Explorer, choose “Properties,” then look for the “Startup object” setting under the “Application” tab). (This was also mentioned by Bahri Gungor)
Turn off auto-generation of App.g.cs’s static Main() method—In Solution Explorer, right click on App.xaml, choose “Properties,” then change the “Build Action” from “ApplicationDefinition” to “Page”.