zoukankan      html  css  js  c++  java
  • WPF中如何重新定义Main函数

    相信大家都知道,Main函数一直都作为程序的入口点,而在开发WPF项目的时候,有些初始化的操作则是想放在Main中去执行,那么当时想试试如果重新写一个Main函数后,程序会不会执行,不过结果很遗憾。

    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Threading.Tasks;
    using System.Windows;
    
    namespace ProductManage
    {
        /// <summary>
        /// App.xaml 的交互逻辑
        /// </summary>
        public partial class App : Application
        {
            /// <summary>
            /// Application Entry Point.
            /// </summary>
            [System.STAThreadAttribute()]
            [System.Diagnostics.DebuggerNonUserCodeAttribute()]
            [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
            public static void Main()
            {        
         
                ProductManage.App app = new ProductManage.App();
                app.InitializeComponent();
                app.Run();
            }
        }
    }

    编译完毕后就会出息如下错误:

    这说明已经存在了一个Main函数了,重复定义便会出现编译错误;

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

    既然重复了,那么删掉原有的Main函数不就行了吗,删完之后,重新运行,果然程序正常运行;不过此时再把项目重新编译一下,还会出现上述Main函数重复定义的错误,治标不治本。

    下面则是正确解决Main函数重复定义的方法

    找到下面Main函数后删除

    然后右键项目->属性得到如下所示:改为Application.App即可

    最后 右键App.xml:生成操作改为Page,然后重新编译项目即可。

  • 相关阅读:
    JS浮点数的加减乘除运算
    鼓励心里的阳光
    mysql创建新用户并分配数据库权限
    CentOS下的Memcache安装步骤(Linux+Nginx+PHP+Memcached)
    Python发送邮件
    SQL操作语句
    Mysql数据库操作语句
    Cookie,Session的区别
    Jmeter性能测试-分布式压力测试
    性能测试指标
  • 原文地址:https://www.cnblogs.com/QingYiShouJiuRen/p/11323049.html
Copyright © 2011-2022 走看看