为什么说程序有多个入口点定义因此用/ main编译以包含入口点的类型?

问题描述:

我们知道VS会自动在app.g.cs类中为wpf窗口应用程序创建一个main函数。我有。现在我将在另一个类中定义自己的main函数,并从app.g.cs类文件中删除默认入口点。我有构建并仍然错误显示您有两个入口点。当我要重建解决方案时,在app.g.cs类中自动创建一个main函数(默认入口点)。我应该怎样做才能停止在app.g.cs文件中自动重新创建主要功能(默认入口点)?



我尝试过:



我正试图解决这个问题。

-------------- --------------------------------

在另一个类

As we know that VS automatically creates a main function in app.g.cs class for a wpf window application. I have so. Now I am going to defined my own main function in another class and removed the default entry point from app.g.cs class file. I have build and still error showing that you have two entry points. When I am going to rebuild the solution, a main function (default entry point) automatically created within the app.g.cs class. What should i need to do to stop automatically recreating of main function (default entry point) within app.g.cs file?

What I have tried:

I am trying to resolve this problem.
----------------------------------------------
The main function which is defined within another class

SingleInstanceManager.cs as 
  class SingleInstanceManager : WindowsFormsApplicationBase
    {

        public SingleInstanceManager()
        {
            this.IsSingleInstance = true;
            //System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon();
            //System.Windows.Forms.NotifyIcon ni1 = new System.Windows.Forms.NotifyIcon();


            //ni1.Icon = Properties.Resources.favicon;
            ////Taskba.OverlayIcon = new Icon(SystemIcons.Error, 16, 16);

            //ni1.Text = "IP Messenger";

            //ni1.Visible = true;


            //    ni.DoubleClick +=
            //delegate(object sender, EventArgs args)
            //{

            //    MainWindow m = new MainWindow();


            //    this.Show();
            //    this.WindowState = WindowState.Normal;
            //};
        }

        protected override bool OnStartup(Microsoft.VisualBasic.ApplicationServices.StartupEventArgs eventArgs)
        {
            base.OnStartup(eventArgs);
            App app = new App();
            app.Run(new Selectlanguage("0"));
            return false;
        }

        protected override void OnStartupNextInstance(
           StartupNextInstanceEventArgs eventArgs)
        {
            base.OnStartupNextInstance(eventArgs);
            Window mainWindow = System.Windows.Application.Current.MainWindow;
            if (mainWindow.WindowState != WindowState.Normal)
            {
                mainWindow.WindowState = WindowState.Normal;
            }
            System.Windows.Application.Current.MainWindow.Activate();
        }

        [STAThread]
        public static void Main(string[] args)
        {
            SingleInstanceManager manager = new SingleInstanceManager();
            manager.Run(args);
        }


    }
------------------------------------
I have removed default entry point from app.g.cs class file and put following code:
/// <summary>
    /// App
    /// 
    public partial class App : System.Windows.Application, System.Windows.Markup.IComponentConnector
    {
        private bool _contentLoaded;
        /// <summary>
        /// InitializeComponent
        /// 
        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
        public void InitializeComponent()
        {

            if (_contentLoaded)
            {
                return;
            }
            _contentLoaded = true;

            #line 4 "..\..\App.xaml"
            this.StartupUri = new System.Uri("Selectlanguage.xaml", System.UriKind.Relative);

            #line default
            #line hidden
            //  System.Uri resourceLocater = new System.Uri("/IDSCANNER;component/app.xaml", System.UriKind.Relative);

            #line 1 "..\..\App.xaml"
            //System.Windows.Application.LoadComponent(this, resourceLocater);

            #line default
            #line hidden
        }

        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
        [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
        [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")]
        [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
        [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            this._contentLoaded = true;
        }
    }

默认入口点位于app.xaml文件中

Default entry point is in the app.xaml file
<Application x:Class="WpfOptionList.App"

             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

             xmlns:local="clr-namespace:WpfOptionList"

             StartupUri="MainWindow.xaml">
    <Application.Resources>
         
    </Application.Resources>
</Application>



删除此内容line:


Remove this line:

StartupUri="MainWindow.xaml"



现在转到属性>申请> StartupName并指向你的bootstrap方法。它涉及更多一点,所以你需要做更多的研究(谷歌搜索)才能做到正确。


Now go to "Properties > Application > StartupName" and point to your bootstrap method.It is a little bit more involved, so you will need to do some more research (google search) to get it right.