Process.SynchronizingObject Eigenschaft
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Dient zum Abrufen oder Festlegen des Objekts, das zum Marshallen der Ereignishandleraufrufe verwendet wird, die als Ergebnis eines Prozessausgangsereignisses ausgegeben werden.
public:
property System::ComponentModel::ISynchronizeInvoke ^ SynchronizingObject { System::ComponentModel::ISynchronizeInvoke ^ get(); void set(System::ComponentModel::ISynchronizeInvoke ^ value); };
public System.ComponentModel.ISynchronizeInvoke? SynchronizingObject { get; set; }
public System.ComponentModel.ISynchronizeInvoke SynchronizingObject { get; set; }
[System.ComponentModel.Browsable(false)]
public System.ComponentModel.ISynchronizeInvoke SynchronizingObject { get; set; }
member this.SynchronizingObject : System.ComponentModel.ISynchronizeInvoke with get, set
[<System.ComponentModel.Browsable(false)>]
member this.SynchronizingObject : System.ComponentModel.ISynchronizeInvoke with get, set
Public Property SynchronizingObject As ISynchronizeInvoke
Eigenschaftswert
Wird ISynchronizeInvoke verwendet, um Ereignishandleraufrufe zu marshallen, die als Ergebnis eines Exited Ereignisses für den Prozess ausgegeben werden.
- Attribute
Beispiele
private MyButton button1;
private void button1_Click(object sender, System.EventArgs e)
{
using (Process myProcess = new Process())
{
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("mspaint");
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();
myProcess.Exited += new EventHandler(MyProcessExited);
// Set 'EnableRaisingEvents' to true, to raise 'Exited' event when process is terminated.
myProcess.EnableRaisingEvents = true;
// Set method handling the exited event to be called ;
// on the same thread on which MyButton was created.
myProcess.SynchronizingObject = button1;
MessageBox.Show("Waiting for the process 'mspaint' to exit....");
myProcess.WaitForExit();
}
}
private void MyProcessExited(Object source, EventArgs e)
{
MessageBox.Show("The process has exited.");
}
}
public class MyButton : Button
{
}
Private button1 As MyButton
Private Sub button1_Click(sender As Object, e As EventArgs)
Using myProcess As New Process()
Dim myProcessStartInfo As New ProcessStartInfo("mspaint")
myProcess.StartInfo = myProcessStartInfo
myProcess.Start()
AddHandler myProcess.Exited, AddressOf MyProcessExited
' Set 'EnableRaisingEvents' to true, to raise 'Exited' event when process is terminated.
myProcess.EnableRaisingEvents = True
' Set method handling the exited event to be called ;
' on the same thread on which MyButton was created.
myProcess.SynchronizingObject = button1
MessageBox.Show("Waiting for the process 'mspaint' to exit....")
myProcess.WaitForExit()
End Using
End Sub
Private Sub MyProcessExited(source As Object, e As EventArgs)
MessageBox.Show("The process has exited.")
End Sub
End Class
Public Class MyButton
Inherits Button
End Class
Hinweise
Wenn SynchronizingObject dies der Fall ist null, werden Methoden, die das Exited Ereignis behandeln, in einem Thread aus dem Systemthreadpool aufgerufen. Weitere Informationen zu Systemthreadpools finden Sie unter ThreadPool.
Wenn das Exited Ereignis von einer visuellen Windows Forms-Komponente behandelt wird, z. B. einer Button, die auf die Komponente über den Systemthreadpool zugreift, funktioniert möglicherweise nicht oder führt zu einer Ausnahme. Vermeiden Sie dies durch Festlegen SynchronizingObject auf eine Windows Forms-Komponente, wodurch die Methoden, die das Exited Ereignis behandeln, für denselben Thread aufgerufen werden, auf dem die Komponente erstellt wurde.
Wenn die Process In Visual Studio 2005 in einem Windows Forms-Designer verwendet wird, wird automatisch auf das Steuerelement festgelegt, SynchronizingObject das das ProcessSteuerelement enthält. Wenn Sie z. B. einen Process Designer für Form1 (der von Form) erbt, wird die SynchronizingObject Eigenschaft Process auf die Instanz von Form1:
process1.StartInfo.Domain = "";
process1.StartInfo.LoadUserProfile = false;
process1.StartInfo.Password = null;
process1.StartInfo.StandardErrorEncoding = null;
process1.StartInfo.StandardOutputEncoding = null;
process1.StartInfo.UserName = "";
process1.SynchronizingObject = this;
process1.StartInfo.Domain <- "";
process1.StartInfo.LoadUserProfile <- false;
process1.StartInfo.Password <- null;
process1.StartInfo.StandardErrorEncoding <- null;
process1.StartInfo.StandardOutputEncoding <- null;
process1.StartInfo.UserName <- "";
process1.SynchronizingObject <- this;
process1.StartInfo.Domain = ""
process1.StartInfo.LoadUserProfile = False
process1.StartInfo.Password = Nothing
process1.StartInfo.StandardErrorEncoding = Nothing
process1.StartInfo.StandardOutputEncoding = Nothing
process1.StartInfo.UserName = ""
process1.SynchronizingObject = Me
In der Regel wird diese Eigenschaft festgelegt, wenn die Komponente innerhalb eines Steuerelements oder Formulars platziert wird, da diese Komponenten an einen bestimmten Thread gebunden sind.