System.ComponentModel.ISynchronizeInvoke Interface

Assembly: System.dll
Namespace: System.ComponentModel
Summary
Provides a way to synchronously or asynchronously execute a delegate.
C# Syntax:
public interface ISynchronizeInvoke
Remarks
The ISynchronizeInvoke interface provides synchronous and asynchronous communication between objects about the occurrence of an event. Objects that implement this interface can receive notification that an event has occurred, and they can respond to queries about the event. In this way, clients can make sure that one request has been processed before they submit a subsequent request that depends on completion of the first.

The ISynchronizeInvoke class provides two ways to invoke a process:

  1. Asynchronously, by using the ISynchronizeInvoke.BeginInvoke method. ISynchronizeInvoke.BeginInvoke starts a process and then returns immediately. Use ISynchronizeInvoke.EndInvoke to wait until the process started by ISynchronizeInvoke.BeginInvoke completes.
  2. Synchronously, by using the ISynchronizeInvoke.Invoke method. ISynchronizeInvoke.Invoke starts a process, waits until it completes, and then returns. Use ISynchronizeInvoke.Invoke when the control's main thread is different from the calling thread to marshal the call to the proper thread.
See also:
System.ComponentModel Namespace | ISynchronizeInvoke.BeginInvoke | ISynchronizeInvoke.EndInvoke | ISynchronizeInvoke.Invoke

System.ComponentModel.ISynchronizeInvoke Member List:

Public Properties
InvokeRequired Read-only

Gets a value indicating whether the caller must call ISynchronizeInvoke.Invoke when calling an object that implements this interface.
Public Methods
BeginInvoke Executes the delegate on the main thread that this object executes on.
EndInvoke Waits until the process started by calling ISynchronizeInvoke.BeginInvoke completes, and then returns the value generated by the process.
Invoke Executes the delegate on the main thread that this object executes on.

System.ComponentModel.ISynchronizeInvoke Member Details

Property: InvokeRequired (read-only)
Summary
Gets a value indicating whether the caller must call ISynchronizeInvoke.Invoke when calling an object that implements this interface.
C# Syntax:
bool InvokeRequired {get;}
Remarks
This property determines whether the caller must call ISynchronizeInvoke.Invoke when making method calls to an object that implements this interface. Such objects are bound to a specific thread and are not thread-safe. If you are calling a method from a different thread, you must use the ISynchronizeInvoke.Invoke method to marshal the call to the proper thread.

Return to top


Method: BeginInvoke(
   Delegate method,
   object[] args
)
Summary
Executes the delegate on the main thread that this object executes on.
C# Syntax:
IAsyncResult BeginInvoke(
   Delegate method,
   object[] args
);
Parameters:

method

A Delegate to a method that takes parameters of the same number and type that are contained in args.

args

An array of type Object to pass as arguments to the given method. This can be null if no arguments are needed.

Return Value:
An IAsyncResult interface that represents the asynchronous operation started by calling this method.
Remarks
The delegate is called asynchronously, and this method returns immediately. You can call this method from any thread. If you need the return value from a process started with this method, call ISynchronizeInvoke.EndInvoke to get the value.

If you need to call the delegate synchronously, use the ISynchronizeInvoke.Invoke method instead.

See also:
ISynchronizeInvoke.EndInvoke

Return to top


Method: EndInvoke(
   IAsyncResult result
)
Summary
Waits until the process started by calling ISynchronizeInvoke.BeginInvoke completes, and then returns the value generated by the process.
C# Syntax:
object EndInvoke(
   IAsyncResult result
);
Parameters:

result

An IAsyncResult interface that represents the asynchronous operation started by calling ISynchronizeInvoke.BeginInvoke.

Return Value:
An Object that represents the return value generated by the asynchronous operation.
Remarks
This method gets the return value of the asynchronous operation represented by the IAsyncResult passed by this interface. If the asynchronous operation has not completed, this method will wait until the result is available.
See also:
ISynchronizeInvoke.BeginInvoke

Return to top


Method: Invoke(
   Delegate method,
   object[] args
)
Summary
Executes the delegate on the main thread that this object executes on.
C# Syntax:
object Invoke(
   Delegate method,
   object[] args
);
Parameters:

method

A Delegate that contains a method to call, in the context of the thread for the control.

args

An array of type Object that represents the arguments to pass to the given method. This can be null if no arguments are needed.

Return Value:
An Object that represents the return value from the delegate being invoked, or null if the delegate has no return value.
Remarks
Unlike ISynchronizeInvoke.BeginInvoke, this method operates synchronously, that is, it waits until the process completes before returning. Exceptions raised during the call are propagated back to the caller.

Use this method when calling a method from a different thread to marshal the call to the proper thread.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.