相关文章推荐
完美的地瓜  ·  <input type="time"> - ...·  2 月前    · 
怕老婆的仙人球  ·  Sysinternals Desktops ...·  2 年前    · 
public:
 virtual IAsyncResult ^ BeginInvoke(Delegate ^ method, cli::array <System::Object ^> ^ args);
public:
 virtual IAsyncResult ^ BeginInvoke(Delegate ^ method, ... cli::array <System::Object ^> ^ args);
public IAsyncResult BeginInvoke (Delegate method, object[] args);
public IAsyncResult BeginInvoke (Delegate method, params object[] args);
abstract member BeginInvoke : Delegate * obj[] -> IAsyncResult
override this.BeginInvoke : Delegate * obj[] -> IAsyncResult
Public Function BeginInvoke (method As Delegate, args As Object()) As IAsyncResult
Public Function BeginInvoke (method As Delegate, ParamArray args As Object()) As IAsyncResult
delegate void MyDelegate( Label^ myControl, String^ myArg2 ); void Button_Click( Object^ /*sender*/, EventArgs^ /*e*/ ) array<Object^>^myArray = gcnew array<Object^>(2); myArray[ 0 ] = gcnew Label; myArray[ 1 ] = "Enter a Value"; myTextBox->BeginInvoke( gcnew MyDelegate( this, &MyForm::DelegateMethod ), myArray ); void DelegateMethod( Label^ myControl, String^ myCaption ) myControl->Location = Point(16,16); myControl->Size = System::Drawing::Size( 80, 25 ); myControl->Text = myCaption; this->Controls->Add( myControl ); delegate void InvokeDelegate(); public delegate void MyDelegate(Label myControl, string myArg2); private void Button_Click(object sender, EventArgs e) object[] myArray = new object[2]; myArray[0] = new Label(); myArray[1] = "Enter a Value"; myTextBox.BeginInvoke(new MyDelegate(DelegateMethod), myArray); public void DelegateMethod(Label myControl, string myCaption) myControl.Location = new Point(16,16); myControl.Size = new Size(80, 25); myControl.Text = myCaption; this.Controls.Add(myControl); Delegate Sub MyDelegate(myControl As Label, myArg2 As String) Private Sub Button_Click(sender As Object, e As EventArgs) Dim myArray(1) As Object myArray(0) = New Label() myArray(1) = "Enter a Value" myTextBox.BeginInvoke(New MyDelegate(AddressOf DelegateMethod), myArray) End Sub Public Sub DelegateMethod(myControl As Label, myCaption As String) myControl.Location = New Point(16, 16) myControl.Size = New Size(80, 25) myControl.Text = myCaption Me.Controls.Add(myControl) End Sub

委托以异步方式调用,此方法会立即返回。 你可以从任何线程调用此方法,即使是拥有控件句柄的线程。 如果控件的句柄尚不存在,此方法将搜索控件的父链,直到找到具有窗口句柄的控件或窗体。 如果未找到适当的句柄, BeginInvoke 将引发异常。 委托方法中的异常被视为未捕获,并将发送到应用程序的未捕获异常处理程序。

可以调用 EndInvoke 以从委托中检索返回值(如果为 neccesary),但这不是必需的。 EndInvoke 将阻止,直到可以检索返回值。

控件上的大多数方法只能从创建控件的线程调用。 除了 InvokeRequired 属性之外,控件上还有四种方法是线程安全的: Invoke BeginInvoke EndInvoke 以及 CreateGraphics 控件的句柄是否已创建。 在后台线程上创建控件句柄之前调用 CreateGraphics 可能会导致非法跨线程调用。 对于所有其他方法调用,应使用其中一个调用方法封送对控件线程的调用。 调用方法始终在控件的线程上调用其回调。

如果应处理消息的线程不再处于活动状态,则可能会引发异常。

public:
 IAsyncResult ^ BeginInvoke(Action ^ method);
public IAsyncResult BeginInvoke (Action method);
member this.BeginInvoke : Action -> IAsyncResult
Public Function BeginInvoke (method As Action) As IAsyncResult
public:
 IAsyncResult ^ BeginInvoke(Delegate ^ method);
public IAsyncResult BeginInvoke (Delegate method);
member this.BeginInvoke : Delegate -> IAsyncResult
Public Function BeginInvoke (method As Delegate) As IAsyncResult
void Invoke_Click( Object^ /*sender*/, EventArgs^ /*e*/ ) myTextBox->BeginInvoke( gcnew InvokeDelegate( this, &MyForm::InvokeMethod ) ); void InvokeMethod() myTextBox->Text = "Executed the given delegate"; public delegate void InvokeDelegate(); private void Invoke_Click(object sender, EventArgs e) myTextBox.BeginInvoke(new InvokeDelegate(InvokeMethod)); public void InvokeMethod() myTextBox.Text = "Executed the given delegate"; Delegate Sub InvokeDelegate() Private Sub Invoke_Click(sender As Object, e As EventArgs) myTextBox.BeginInvoke(New InvokeDelegate(AddressOf InvokeMethod)) End Sub Public Sub InvokeMethod() myTextBox.Text = "Executed the given delegate" End Sub

委托以异步方式调用,此方法会立即返回。 你可以从任何线程调用此方法,即使是拥有控件句柄的线程。 如果控件的句柄尚不存在,此方法将搜索控件的父链,直到找到具有窗口句柄的控件或窗体。 如果未找到适当的句柄, BeginInvoke 将引发异常。 委托方法中的异常被视为未捕获,并将发送到应用程序的未捕获异常处理程序。

可以调用 EndInvoke 以从委托中检索返回值(如果为 neccesary),但这不是必需的。 EndInvoke 将阻止,直到可以检索返回值。

控件上的大多数方法只能从创建控件的线程调用。 除了 InvokeRequired 属性之外,控件上还有四种方法是线程安全的: Invoke BeginInvoke EndInvoke 以及 CreateGraphics 控件的句柄是否已创建。 在后台线程上创建控件句柄之前调用 CreateGraphics 可能会导致非法跨线程调用。 对于所有其他方法调用,应使用其中一个调用方法封送对控件线程的调用。 调用方法始终在控件的线程上调用其回调。

如果应处理消息的线程不再处于活动状态,则可能会引发异常。