Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

more than one entry point defined, so which Main to delete?

$
0
0

I am going through the book "Illustrated WPF" in order to learn more about WPF.  In one of the examples, I get the above error.  I found out why it was happening and fixed it so that the program works now.  However, I am unsure whether or not I got rid of the right Main.  To further clarify, I input the following code from the book into VS2010:

namespace WpfEventHandling
{
    /// <summary>
    /// Interaction logic for MyWindow.xaml
    /// </summary>
    public partial class MyWindow : Window
    {
        public MyWindow() //create constructor
        {
            Width = 300; //set width property
            Height = 200; //set height property
            Title = "My Program Window"; //set Title property
            Content = "This application handles the Startup event"; //set content property
        }
    }
    public class Program
    {
        static void App_Startup(object sender, StartupEventArgs args) //App_Startup is the startup event handler
        {
            MessageBox.Show("The application is starting.", "Starting Message");
        }

        [STAThread]
        static void Main()
        {
            MyWindow win = new MyWindow(); //create MainWindow object

            Application app = new Application(); //create new Application object

            //adds the handler to the event
            app.Startup += App_Startup; //app.Startup is the event; App_Startup is the handler
            app.Run(win);  //run the win object
        }
    }
}

When I ran it I received the following error:

Error    1    Program 'C:\Users\***\Desktop\WPF\WpfEventHandling\WpfEventHandling\obj\x86\Debug\WpfEventHandling.exe' has more than one entry point defined: 'WpfEventHandling.Program.Main()'.  Compile with /main to specify the type that contains the entry point.    C:\Users\***\Desktop\WPF\WpfEventHandling\WpfEventHandling\MyWindow.xaml.cs    38    21    WpfEventHandling

I found where the second Main() method was.  It had been auto-generated in the App.g.cs file.  So I commented that section of the code out. However, after I did that and rebuilt the program, I was given a warning telling me that making changes to that file can cause problems.

I went ahead and did it anyway just to see what would happen.  The program works fine.  After all that long-windedness, my question is, was that the proper way to have handled the situation or should I have commented out the Main method in the  MyWindow.xaml.cs file and input the required Main method code into the Main method of the App.g.cs file?


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>