Application.Run Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Démarre une application Windows Presentation Foundation.
Surcharges
| Nom | Description |
|---|---|
| Run(Window) |
Démarre une application Windows Presentation Foundation et ouvre la fenêtre spécifiée. |
| Run() |
Démarre une application Windows Presentation Foundation. |
Run(Window)
Démarre une application Windows Presentation Foundation et ouvre la fenêtre spécifiée.
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
Paramètres
Retours
Code Int32 de sortie de l’application retourné au système d’exploitation lorsque l’application s’arrête. Par défaut, la valeur du code de sortie est 0.
- Attributs
Exceptions
Run() est appelé à partir d’une application hébergée par un navigateur (par exemple, une application de navigateur XAML (XBAP)).
Exemples
L’exemple suivant montre une application avec une méthode de point d’entrée statique créée manuellement qui instancie Application, avant d’appeler 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
Remarques
Cette surcharge étend la Run méthode pour ouvrir la fenêtre spécifiée une fois qu’une application a commencé à s’exécuter.
Si vous définissez un code Application qui ouvre une fenêtre au démarrage de l’exécution, vous appelez Runexplicitement .
Si vous créez votre Application balisage à l’aide du balisage ou du balisage et du code-behind, vous pouvez ouvrir automatiquement une fenêtre pendant l’une des techniques suivantes :
De manière déclarative, en définissant StartupUri.
Par programmation, en gérant Startup.
Voir aussi
S’applique à
Run()
Démarre une application Windows Presentation Foundation.
public:
int Run();
public int Run();
member this.Run : unit -> int
Public Function Run () As Integer
Retours
Code Int32 de sortie de l’application retourné au système d’exploitation lorsque l’application s’arrête. Par défaut, la valeur du code de sortie est 0.
Exceptions
Run() est appelé à partir d’une application hébergée par un navigateur (par exemple, une application de navigateur XAML (XBAP)).
Exemples
L’exemple suivant montre une application qui utilise une application personnalisée Application et doit donc appeler Runexplicitement .
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
Remarques
Run est appelé pour démarrer une application WPF. Si vous définissez votre Application utilisation du balisage ou du balisage et du code-behind, Run vous serez appelé implicitement. Toutefois, si vous définissez votre Application code à l’aide, vous devez appeler Runexplicitement .
Quand Run elle est appelée, Application attache une nouvelle Dispatcher instance au thread d’interface utilisateur. Ensuite, la méthode de l’objet DispatcherRun est appelée, ce qui démarre une pompe de messages pour traiter les messages windows. Enfin, l’objet Dispatcher appelle la Application méthode de l’objet OnStartup pour déclencher l’événement Startup . Par conséquent, le modèle d’exécution de l’application a été établi au moment où vous gérez Startup, à quel moment l’application est considérée comme en cours d’exécution.
Une application cesse de s’exécuter lorsqu’elle Shutdown est appelée ; la valeur de la ShutdownMode propriété détermine quand Shutdown elle est appelée et si elle se produit automatiquement ou si vous devez l’appeler explicitement.
Run peut être appelé uniquement à partir du thread qui crée l’objet Application . En outre, Run ne peut pas être appelé à partir d’un XBAP.