Application.Run 메서드

정의

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

오버로드

Run()

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

Run(Window)

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

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

설명

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

가 호출되면 RunApplicationDispatcher instance UI 스레드에 연결합니다. 다음으로, Dispatcher 창 메시지를 처리하기 위해 메시지 펌프를 시작하는 개체의 Run 메서드가 호출됩니다. 마지막으로 개체는 Dispatcher 개체의 메서드를 OnStartup 호출 Application 하여 이벤트를 발생합니다Startup. 따라서 애플리케이션 실행 모델 이미 처리할 때 설정 되었으며 Startup,이 시점에서 애플리케이션 실행으로 간주 됩니다.

애플리케이션의 경우 실행이 중지 Shutdown 가 호출 되 값을 ShutdownMode 속성을 결정 하는 경우 Shutdown 호출 되 고 자동으로 수행 하거나 명시적으로 해야 하는지 여부를 호출 합니다.

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

추가 정보

적용 대상

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 브라우저 애플리케이션))에서 호출됩니다.

예제

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

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.

추가 정보

적용 대상