Application 클래스

정의

애플리케이션을 시작 및 중지하는 메서드, Windows 메시지를 처리하는 메서드, 애플리케이션에 대한 정보를 가져오는 속성 등 애플리케이션을 관리하는 static 메서드 및 속성을 제공합니다. 이 클래스는 상속할 수 없습니다.

public ref class Application sealed
public sealed class Application
type Application = class
Public NotInheritable Class Application
상속
Application

예제

다음 코드 예제에서는 폼의 목록 상자에 숫자를 나열합니다. 클릭 button1할 때마다 애플리케이션은 목록에 다른 번호를 추가합니다.

메서드 RunMainlistBox1button1을 만드는 애플리케이션을 시작하고 . 사용자가 클릭하면 button1메서드에 button1_Click .가 MessageBox표시됩니다. 사용자가 클릭하면 NoMessageBox메서드가 button1_Click 목록에 숫자를 추가합니다. 사용자가 클릭하면 애플리케이션은 큐에 남아 있는 모든 메시지를 처리한 다음 종료하도록 호출 Exit 합니다Yes.

메모

호출 Exit 이 부분 신뢰에서 실패합니다.

public ref class Form1: public System::Windows::Forms::Form
{
private:
   Button^ button1;
   ListBox^ listBox1;

public:
   Form1()
   {
      button1 = gcnew Button;
      button1->Left = 200;
      button1->Text =  "Exit";
      button1->Click += gcnew EventHandler( this, &Form1::button1_Click );
      listBox1 = gcnew ListBox;
      this->Controls->Add( button1 );
      this->Controls->Add( listBox1 );
   }

private:
   void Form1::button1_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      int count = 1;
      
      // Check to see whether the user wants to exit 
      // the application. If not, add a number to the list box.
      while ( MessageBox::Show(  "Exit application?",  "", MessageBoxButtons::YesNo ) == ::DialogResult::No )
      {
         listBox1->Items->Add( count );
         count += 1;
      }

      
      // The user wants to exit the application. 
      // Close everything down.
      Application::Exit();
   }

};

int main()
{
   
   // Starts the application.
   Application::Run( gcnew Form1 );
}
public class Form1 : Form
{
    [STAThread]
    public static void Main()
    {
        // Start the application.
        Application.Run(new Form1());
    }

    private Button button1;
    private ListBox listBox1;

    public Form1()
    {
        button1 = new Button();
        button1.Left = 200;
        button1.Text = "Exit";
        button1.Click += new EventHandler(button1_Click);

        listBox1 = new ListBox();
        this.Controls.Add(button1);
        this.Controls.Add(listBox1);
    }

    private void button1_Click(object sender, System.EventArgs e)
    {
        int count = 1;
        // Check to see whether the user wants to exit the application.
        // If not, add a number to the list box.
        while (MessageBox.Show("Exit application?", "",
            MessageBoxButtons.YesNo)==DialogResult.No)
        {
            listBox1.Items.Add(count);
            count += 1;
        }

        // The user wants to exit the application.
        // Close everything down.
        Application.Exit();
    }
}
Public Class Form1 
    Inherits Form

    <STAThread()> _
     Shared Sub Main()
        ' Start the application.
        Application.Run(New Form1)
    End Sub

    Private WithEvents button1 As Button
    Private WithEvents listBox1 As ListBox

    Public Sub New()
        button1 = New Button
        button1.Left = 200
        button1.Text = "Exit"

        listBox1 = New ListBox
        Me.Controls.Add(button1)
        Me.Controls.Add(listBox1)
    End Sub

    Private Sub button1_Click(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles button1.Click
        Dim count As Integer = 1
        ' Check to see whether the user wants to exit the application.
        ' If not, add a number to the list box.
        While (MessageBox.Show("Exit application?", "", _
            MessageBoxButtons.YesNo) = DialogResult.No)

            listBox1.Items.Add(count)
            count += 1

        End While

        ' The user wants to exit the application. 
        ' Close everything down.
        Application.Exit()
    End Sub

End Class

설명

Application 클래스에는 다음과 같이 애플리케이션과 스레드를 시작 및 중지하고 Windows 메시지를 처리하는 메서드가 있습니다.

  • Run 는 현재 스레드에서 애플리케이션 메시지 루프를 시작하고 필요에 따라 폼을 표시합니다.

  • Exit 또는 ExitThread 메시지 루프를 중지합니다.

  • DoEvents 는 프로그램이 루프에 있는 동안 메시지를 처리합니다.

  • AddMessageFilter 애플리케이션 메시지 펌프에 메시지 필터를 추가하여 Windows 메시지를 모니터링합니다.

  • IMessageFilter 를 사용하면 이벤트 처리기를 호출하기 전에 이벤트가 발생하지 않도록 하거나 특수 작업을 수행할 수 있습니다.

이 클래스에는 CurrentCulture 현재 스레드에 대한 문화권 정보를 얻거나 설정하는 속성이 있습니다 CurrentInputLanguage .

이 클래스의 인스턴스를 만들 수 없습니다.

속성

Name Description
AllowQuit

호출자가 이 애플리케이션을 종료할 수 있는지 여부를 나타내는 값을 가져옵니다.

CommonAppDataPath

모든 사용자 간에 공유되는 애플리케이션 데이터의 경로를 가져옵니다.

CommonAppDataRegistry

모든 사용자 간에 공유되는 애플리케이션 데이터의 레지스트리 키를 가져옵니다.

CompanyName

애플리케이션과 연결된 회사 이름을 가져옵니다.

CurrentCulture

현재 스레드의 문화권 정보를 가져오거나 설정합니다.

CurrentInputLanguage

현재 스레드의 현재 입력 언어를 가져오거나 설정합니다.

ExecutablePath

실행 파일을 포함하여 애플리케이션을 시작한 실행 파일의 경로를 가져옵니다.

LocalUserAppDataPath

로밍이 아닌 로컬 사용자의 애플리케이션 데이터에 대한 경로를 가져옵니다.

MessageLoop

이 스레드에 메시지 루프가 있는지 여부를 나타내는 값을 가져옵니다.

OpenForms

애플리케이션이 소유한 열린 양식의 컬렉션을 가져옵니다.

ProductName

이 애플리케이션과 연결된 제품 이름을 가져옵니다.

ProductVersion

이 애플리케이션과 연결된 제품 버전을 가져옵니다.

RenderWithVisualStyles

현재 애플리케이션이 비주얼 스타일을 사용하여 컨트롤을 그리는지 여부를 지정하는 값을 가져옵니다.

SafeTopLevelCaptionFormat

경고 배너와 함께 표시될 때 최상위 창 캡션에 적용할 형식 문자열을 가져오거나 설정합니다.

StartupPath

실행 파일을 포함하지 않고 애플리케이션을 시작한 실행 파일의 경로를 가져옵니다.

UserAppDataPath

사용자의 애플리케이션 데이터에 대한 경로를 가져옵니다.

UserAppDataRegistry

사용자의 애플리케이션 데이터에 대한 레지스트리 키를 가져옵니다.

UseWaitCursor

대기 커서가 열려 있는 모든 애플리케이션 형식에 사용되는지 여부를 가져오거나 설정합니다.

VisualStyleState

애플리케이션 창에 비주얼 스타일을 적용하는 방법을 지정하는 값을 가져옵니다.

메서드

Name Description
AddMessageFilter(IMessageFilter)

메시지 필터를 추가하여 Windows 메시지가 대상으로 라우팅될 때 모니터링합니다.

DoEvents()

현재 메시지 큐에 있는 모든 Windows 메시지를 처리합니다.

EnableVisualStyles()

애플리케이션에 비주얼 스타일을 사용하도록 설정합니다.

Equals(Object)

지정한 개체와 현재 개체가 같은지 여부를 확인합니다.

(다음에서 상속됨 Object)
Exit()

모든 메시지 펌프는 종료해야 하며 메시지가 처리된 후 모든 애플리케이션 창을 닫습니다.

Exit(CancelEventArgs)

모든 메시지 펌프는 종료해야 하며 메시지가 처리된 후 모든 애플리케이션 창을 닫습니다.

ExitThread()

현재 스레드에서 메시지 루프를 종료하고 스레드의 모든 창을 닫습니다.

FilterMessage(Message)

창 메시지에 대해 필터를 실행하고 수정된 메시지의 복사본을 반환합니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
OleRequired()

현재 스레드에서 OLE를 초기화합니다.

OnThreadException(Exception)

ThreadException 이벤트를 발생시킵니다.

RaiseIdle(EventArgs)

호스트된 Idle 시나리오에서 이벤트를 발생합니다.

RegisterMessageLoop(Application+MessageLoopCallback)

메시지 루프가 호스트된 환경에서 실행되고 있는지 여부를 확인하기 위한 콜백을 등록합니다.

RemoveMessageFilter(IMessageFilter)

애플리케이션의 메시지 펌프에서 메시지 필터를 제거합니다.

Restart()

애플리케이션을 종료하고 새 인스턴스를 즉시 시작합니다.

Run()

양식 없이 현재 스레드에서 표준 애플리케이션 메시지 루프 실행을 시작합니다.

Run(ApplicationContext)

를 사용하여 현재 스레드 ApplicationContext에서 표준 애플리케이션 메시지 루프 실행을 시작합니다.

Run(Form)

현재 스레드에서 표준 애플리케이션 메시지 루프 실행을 시작하고 지정된 양식을 표시합니다.

SetCompatibleTextRenderingDefault(Boolean)

특정 컨트롤에 정의된 속성에 UseCompatibleTextRendering 대한 애플리케이션 전체 기본값을 설정합니다.

SetSuspendState(PowerState, Boolean, Boolean)

시스템을 일시 중단하거나 최대 절전 모드로 전환하거나 시스템을 일시 중단하거나 최대 절전 모드로 전환할 것을 요청합니다.

SetUnhandledExceptionMode(UnhandledExceptionMode, Boolean)

필요에 따라 스레드별 동작을 적용하여 처리되지 않은 예외에 대응하는 방법을 애플리케이션에 지시합니다.

SetUnhandledExceptionMode(UnhandledExceptionMode)

처리되지 않은 예외에 대응하는 방법을 애플리케이션에 지시합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)
UnregisterMessageLoop()

로 만든 메시지 루프 콜백을 등록 취소합니다 RegisterMessageLoop(Application+MessageLoopCallback).

이벤트

Name Description
ApplicationExit

애플리케이션을 종료하려고 할 때 발생합니다.

EnterThreadModal

애플리케이션이 모달 상태로 들어가려고 할 때 발생합니다.

Idle

애플리케이션이 처리를 완료하고 유휴 상태로 전환하려고 할 때 발생합니다.

LeaveThreadModal

애플리케이션이 모달 상태를 유지하려고 할 때 발생합니다.

ThreadException

언트래핑된 스레드 예외가 throw되면 발생합니다.

ThreadExit

스레드가 종료되려고 할 때 발생합니다. 애플리케이션의 주 스레드가 종료될 때 이 이벤트가 먼저 발생한 다음 ApplicationExit 이벤트가 발생합니다.

적용 대상