Application.Run 메서드

정의

Windows Presentation Foundation 애플리케이션을 시작합니다.

오버로드

Run(Window)

Windows Presentation Foundation 애플리케이션을 시작하고 지정된 창을 엽니다.

Run()

Windows Presentation Foundation 애플리케이션을 시작합니다.

Run(Window)

Windows Presentation Foundation 애플리케이션을 시작하고 지정된 창을 엽니다.

public:
 int Run(System::Windows::Window ^ window);
[System.Security.SecurityCritical]
public int Run (System.Windows.Window window);
public int Run (System.Windows.Window window);
[<System.Security.SecurityCritical>]
member this.Run : System.Windows.Window -> int
member this.Run : System.Windows.Window -> int
Public Function Run (window As Window) As Integer

매개 변수

window
Window

애플리케이션이 시작될 때 자동으로 열리는 Window.

반환

애플리케이션이 종료되면 운영 체제로 반환되는 Int32 애플리케이션 종료 코드입니다. 기본적으로 종료 코드 값은 0입니다.

특성

예외

Run() 브라우저 호스팅 애플리케이션(예: XBAP(XAML 브라우저 애플리케이션))에서 호출됩니다.

예제

다음 예제에서는 Run호출하기 전에 Application인스턴스화하는 수동으로 만든 정적 진입점 메서드가 있는 애플리케이션을 보여줍니다.

using System;
using System.Windows;

namespace CSharp
{
    public class EntryPoint
    {
        // All WPF applications should execute on a single-threaded apartment (STA) thread
        [STAThread]
        public static void Main()
        {
            Application app = new Application();
            app.Run(new Window());
        }
    }
}

Imports System.Windows

Namespace VisualBasic
    Public Class EntryPoint
        ' All WPF applications should execute on a single-threaded apartment (STA) thread
        <STAThread()>
              Public Shared Sub Main()
            Dim app As New Application()
            app.Run(New Window())
        End Sub
    End Class
End Namespace

설명

이 오버로드는 Run 메서드를 확장하여 애플리케이션 실행을 시작한 후 지정된 창을 엽니다.

실행이 시작될 때 창을 여는 코드 Application 정의하는 경우 명시적으로 Run호출합니다.

태그 또는 태그 및 코드 숨김을 사용하여 Application 만드는 경우 다음 기술 중 하나를 사용하는 동안 창을 자동으로 열 수 있습니다.

  • 선언적으로 StartupUri설정합니다.

  • 프로그래밍 방식으로 Startup처리합니다.

추가 정보

적용 대상

Run()

Windows Presentation Foundation 애플리케이션을 시작합니다.

public:
 int Run();
public int Run ();
member this.Run : unit -> int
Public Function Run () As Integer

반환

애플리케이션이 종료되면 운영 체제로 반환되는 Int32 애플리케이션 종료 코드입니다. 기본적으로 종료 코드 값은 0입니다.

예외

Run() 브라우저 호스팅 애플리케이션(예: XBAP(XAML 브라우저 애플리케이션))에서 호출됩니다.

예제

다음 예제에서는 사용자 지정 Application 사용하므로 명시적으로 Run호출해야 하는 애플리케이션을 보여줍니다.

using System;
using System.Windows;

namespace CSharp
{
    public class EntryPoint1
    {
        // All WPF applications should execute on a single-threaded apartment (STA) thread
        [STAThread]
        public static void Main()
        {
            CustomApplication app = new CustomApplication();
            app.Run();
        }
    }

    public class CustomApplication : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            Window window = new Window();
            window.Show();
        }
    }
}

Imports System.Windows

Namespace VisualBasic
    Public Class EntryPoint
        ' All WPF applications should execute on a single-threaded apartment (STA) thread
        <STAThread()>
              Public Shared Sub Main()
            Dim app As New CustomApplication()
            app.Run()
        End Sub
    End Class

    Public Class CustomApplication
        Inherits Application
        Protected Overrides Sub OnStartup(ByVal e As StartupEventArgs)
            MyBase.OnStartup(e)

            Dim window As New Window()
            window.Show()
        End Sub
    End Class
End Namespace

설명

WPF 애플리케이션을 시작하기 위해 Run 호출됩니다. 태그 또는 태그 및 코드 숨김을 사용하여 Application 정의하는 경우 Run 암시적으로 호출됩니다. 그러나 코드를 사용하여 Application 정의하는 경우 Run명시적으로 호출해야 합니다.

Run 호출되면 ApplicationDispatcher 인스턴스를 UI 스레드에 연결합니다. 다음으로, Dispatcher 개체의 Run 메서드가 호출되어 windows 메시지를 처리하는 메시지 펌프를 시작합니다. 마지막으로 Dispatcher 개체는 Application 개체의 OnStartup 메서드를 호출하여 Startup 이벤트를 발생합니다. 따라서 애플리케이션 실행 모델은 Startup처리할 때까지 설정되었으며, 이때 애플리케이션이 실행 중인 것으로 간주됩니다.

Shutdown 호출되면 애플리케이션 실행이 중지됩니다. ShutdownMode 속성의 값은 Shutdown 호출되는 시기와 자동으로 수행되는지 또는 명시적으로 호출해야 하는지를 결정합니다.

Run Application 개체를 만드는 스레드에서만 호출할 수 있습니다. 또한 Run XBAP에서 호출할 수 없습니다.

추가 정보

적용 대상