어떤 경우에 WPF프로그램이 화면이 안나오고 로직을 수행후 바로 종료되어야 하는 경우가 있습니다.
예를 들어 특정 파일 생성 및 기록 또는 레지스트리에 값을 쓰는 경우 등입니다.
이럴경우에 간단하게 사용하는 방법입니다. Linux 쉘 프로그램과 비슷하다고 생각하면 됩니다.
[App.xaml]
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<!--StartupUri="MainWindow.xaml">-->
<Application.Resources>
</Application.Resources>
</Application>
[App.xaml.cs]
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
//My Code here
//Do something Task
//This Program close(exit) automatically
Environment.Exit(0);
}
}
}
출처 : 다년간의 프로그램밍 경험
'C#(CSharp) > WPF' 카테고리의 다른 글
다국어 작업(Globalization, Localization) (0) | 2015.04.02 |
---|---|
Mutex를 이용해서 1개의 프로세스만 동작하도록 하기 (0) | 2015.03.22 |
UI 쓰레드 (UI Thread) (0) | 2015.03.21 |
Hidden/Collapsed 차이 (0) | 2015.03.21 |
여러 줄 TextBox 컨트롤 만들기 (0) | 2015.03.21 |