WPF应用程序不会运行UI / MainWindow(更新:等待6+分钟后开始!)

时间:2016-02-11 00:16:38

标签: c# wpf

我在Visual Studio(Community 2015)中创建了一个新的WPF应用程序来进行一些非常简单的测试。但是,该应用程序不会启动。

我确实没有改变任何东西,它是原始的空项目,只需使用MainWindow.xaml,App.xaml等(Checked startup URI :)

<Application x:Class="Sandbox2.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:Sandbox2"
             StartupUri="MainWindow.xaml">
    <Application.Resources>

    </Application.Resources>
</Application>

和App.xaml.cs

using System.Windows;

namespace Sandbox2
{
    public partial class App : Application
    {
    }
}

主窗口.xaml:

<Window x:Class="Sandbox2.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:Sandbox2"
    mc:Ignorable="d"
    Title="MainWindow" Height="350" Width="525">
    <Grid>

    </Grid>
</Window>

MainWindows.cs:

使用System.Windows;

namespace Sandbox2
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }
}

任务管理器显示.exe已启动,但它几乎没有使用内存: enter image description here

没有窗口打开,关闭它的唯一方法是通过任务管理器。窗口构造函数中的断点在&#34; InitializeComponent&#34;永远不会被击中。

我很难过,我认为我的项目配置错误,但它只是所有的默认设置。我无法在Stackoverflow或google上找到任何相似内容......任何人都知道为什么会这样?

编辑:我挖掘了App.xaml.cs生成的代码,一直到app.g.i.cs. &#34; Main&#34;中的断点永远不会被击中!

#pragma checksum "..\..\App.xaml" "{406ea660-64cf-4c82-b6f0-42d48172a799}" "2BDF5940107DE9786768C3CB1E5EB012"
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using Sandbox2;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Effects;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;
using System.Windows.Media.TextFormatting;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Shell;


namespace Sandbox2 {


    /// <summary>
    /// App
    /// </summary>
    public partial class App : System.Windows.Application {

        /// <summary>
        /// InitializeComponent
        /// </summary>
        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
        public void InitializeComponent() {

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

            #line default
            #line hidden
        }

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

编辑2 是的,正式确实很糟糕。有用。我让它坐了10分钟,主线程开始了。经过6分钟38秒......没事。 (再次,这次8:24!)

你可以在这里看到,内存从它几百kb的闲置中飙升到合理的数量。 Main方法断点被击中,当我继续时,程序以我的空窗口启动!

究竟是什么导致这种情况?

enter image description here

1 个答案:

答案 0 :(得分:0)

任何未来的人都会遇到同样的问题。它现在全部修好了。我很抱歉,我不知道为什么。我昨晚放弃了,今天早上登录电脑,启动时间又回到了一两秒钟。

我能想到的唯一建议就是重启计算机......

正如Abdulkarim Kanaan所暗示的那样,这可能是防病毒的一些怪癖。