[英]How to run a method immediately after starting up the program?
我正在使用C#WPF,但是在启动.exe文件后无法弄清楚如何启动方法。 我已经做了一个控制台应用程序,但是我不想看到任何表格/窗口。
我摆脱了整个MainWindow()
方法,还添加了要在Main()
方法中调用的方法。 我从App.xaml中删除了StartupUri="MainWindow.xaml"
行,并希望该软件在启动时运行Main()
方法,但它会继续从MainWindow.cs
类中调用MainWindow()
方法。 我知道,因为当我放回MainWindow()
方法时,它会执行该方法中的所有内容。
我尝试做的第一件事是将我的方法调用放入MainWindow()
方法中,但是它一直在循环,我不希望这样。 我猜想解决该问题的方法将是无尽的Thread.Sleep()
,但这似乎是一件非常愚蠢的事情。
这是我的Main()
方法的样子:
/// <summary>
/// Application Entry Point.
/// </summary>
[System.STAThreadAttribute()]
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
public static void Main() {
System.Windows.MessageBox.Show("it's working"); //shows this message it this method is called
}
这是整个App.xaml
:
<Application x:Class="PHAutoProcess.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
</Application.Resources>
</Application>
好,你找到了。 您可以将此评论标记为答案,然后... :)
如果您确实创建了控制台应用程序,那么您将没有任何XAML ...可能不是创建控制台应用程序,而是创建WPF应用程序。 尝试在VS中寻找Console-App
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.