This namespace contains the remote delegates and events framework for CoreRemoting, enabling event-driven communication across remoting boundaries.
Namespace: CoreRemoting.RemoteDelegates
Interface for delegate proxy implementations that handle remote delegate invocation.
| Property | Type | Description |
|---|---|---|
HandlerKey |
string |
Unique key identifying the delegate handler |
| Method | Return Type | Description |
|---|---|---|
InvokeDelegate(object[] args) |
object |
Invokes the delegate with specified arguments |
Implemented by: DelegateProxy
Namespace: CoreRemoting.RemoteDelegates
Interface for delegate proxy factories that create and manage remote delegate proxies.
| Method | Return Type | Description |
|---|---|---|
CreateDelegateProxy<TDelegate>() |
IDelegateProxy |
Creates delegate proxy for specified delegate type |
CreateDelegateProxy(Delegate targetDelegate) |
IDelegateProxy |
Creates delegate proxy from existing delegate |
Implemented by: DelegateProxyFactory
Namespace: CoreRemoting.RemoteDelegates
Interface for delegate invokers that can invoke delegates dynamically and safely.
| Method | Return Type | Description |
|---|---|---|
Invoke(Delegate targetDelegate, object[] args) |
object |
Invokes delegate with arguments |
InvokeSafe(Delegate targetDelegate, object[] args) |
object |
Safely invokes delegate with exception handling |
// Safe delegate invocation
var invoker = new SafeDynamicInvoker();
var result = invoker.InvokeSafe(myDelegate, new object[] { param1, param2 });Implemented by: SafeDynamicInvoker, SimpleDynamicInvoker
Namespace: CoreRemoting.RemoteDelegates
Interfaces: IDelegateProxy
Implementation of delegate proxy that handles remote delegate invocation across remoting boundaries.
| Property | Type | Description |
|---|---|---|
HandlerKey |
string |
Unique identifier for the delegate handler |
| Method | Return Type | Description |
|---|---|---|
InvokeDelegate(object[] args) |
object |
Invokes the remote delegate with specified arguments |
Namespace: CoreRemoting.RemoteDelegates
Interfaces: IDelegateProxyFactory
Factory for creating delegate proxies that can be used for remote event subscription and delegate invocation.
| Method | Return Type | Description |
|---|---|---|
CreateDelegateProxy<TDelegate>() |
IDelegateProxy |
Creates delegate proxy for generic delegate type |
CreateDelegateProxy(Delegate targetDelegate) |
IDelegateProxy |
Creates delegate proxy from existing delegate |
Namespace: CoreRemoting.RemoteDelegates
Utility class that handles event subscription and invocation across remoting boundaries.
| Property | Type | Description |
|---|---|---|
DelegateInvoker |
IDelegateInvoker |
Invoker used to call delegates safely |
| Method | Return Type | Description |
|---|---|---|
AddEventHandler(string eventName, Delegate handler) |
void |
Adds event handler for remote event |
RemoveEventHandler(string eventName, Delegate handler) |
void |
Removes event handler for remote event |
InvokeEvent(string eventName, object[] args) |
void |
Invokes event with specified arguments |
Namespace: CoreRemoting.RemoteDelegates
Interfaces: IDelegateInvoker
Safe delegate invoker that provides exception handling and type safety for dynamic delegate invocation.
| Method | Return Type | Description |
|---|---|---|
Invoke(Delegate targetDelegate, object[] args) |
object |
Invokes delegate with arguments |
InvokeSafe(Delegate targetDelegate, object[] args) |
object |
Safely invokes delegate with exception handling |
// Safe invocation
var invoker = new SafeDynamicInvoker();
try
{
var result = invoker.InvokeSafe(myDelegate, args);
// Handle result
}
catch (Exception ex)
{
// Exception from delegate invocation
Console.WriteLine($"Delegate failed: {ex.Message}");
}Namespace: CoreRemoting.RemoteDelegates
Interfaces: IDelegateInvoker
Simple delegate invoker that provides basic dynamic delegate invocation without extensive error handling.
| Method | Return Type | Description |
|---|---|---|
Invoke(Delegate targetDelegate, object[] args) |
object |
Invokes delegate with arguments |
InvokeSafe(Delegate targetDelegate, object[] args) |
object |
Safely invokes delegate with minimal exception handling |
// Simple fast invocation
var invoker = new SimpleDynamicInvoker();
var result = invoker.Invoke(myDelegate, args);Namespace: CoreRemoting.RemoteDelegates
Information about a client-side delegate registered for remote invocation.
| Property | Type | Description |
|---|---|---|
Delegate |
Delegate |
The actual delegate object |
HandlerKey |
string |
Unique key identifying the delegate handler |
DelegateType |
Type |
Type of the delegate |
Namespace: CoreRemoting.RemoteDelegates
Registry for managing client-side delegates that can be invoked remotely from the server.
| Method | Return Type | Description |
|---|---|---|
RegisterDelegate(Delegate targetDelegate) |
string |
Registers delegate and returns handler key |
GetDelegateByHandlerKey(string handlerKey) |
Delegate |
Gets delegate by handler key |
UnregisterDelegate(string handlerKey) |
bool |
Unregisters delegate by handler key |
Clear() |
void |
Clears all registered delegates |
Namespace: CoreRemoting.RemoteDelegates
Information about a remote delegate for tracking and management purposes.
| Property | Type | Description |
|---|---|---|
HandlerKey |
string |
Unique key for the delegate handler |
DelegateType |
Type |
Type information for the delegate |
MethodName |
string |
Name of the method the delegate represents |
Namespace: CoreRemoting.RemoteDelegates
Aggregates and manages remote delegate invocations, providing efficient event distribution.
| Method | Return Type | Description |
|---|---|---|
RegisterHandler(string handlerKey, Delegate handler) |
void |
Registers handler for remote delegate |
UnregisterHandler(string handlerKey) |
void |
Unregisters handler |
InvokeHandler(string handlerKey, object[] args) |
object |
Invokes handler with arguments |
public interface IStockService
{
event EventHandler<StockUpdateEventArgs> StockUpdated;
event Action<string> StockAlert;
void UpdateStock(string symbol, decimal price);
}
public class StockService : IStockService
{
public event EventHandler<StockUpdateEventArgs> StockUpdated;
public event Action<string> StockAlert;
public void UpdateStock(string symbol, decimal price)
{
// Update stock data
// Raise events - these will be sent to subscribed clients
StockUpdated?.Invoke(this, new StockUpdateEventArgs(symbol, price));
if (price > 100m)
{
StockAlert?.Invoke($"High price alert: {symbol} at {price}");
}
}
}// Create proxy to remote service
var stockService = client.CreateProxy<IStockService>();
// Subscribe to events
stockService.StockUpdated += (sender, args) =>
{
Console.WriteLine($"Stock updated: {args.Symbol} = {args.Price}");
};
stockService.StockAlert += (message) =>
{
Console.WriteLine($"ALERT: {message}");
};
// Call service method that triggers events
stockService.UpdateStock("AAPL", 150.25m);// Service interface with callback
public interface IProcessingService
{
event Action<ProcessingResult> ProcessingCompleted;
void StartProcessing(string data, Action<int> progressCallback);
}
// Client usage
var processingService = client.CreateProxy<IProcessingService>();
// Subscribe to completion event
processingService.ProcessingCompleted += (result) =>
{
Console.WriteLine($"Processing completed: {result.Status}");
};
// Call with progress callback
processingService.StartProcessing("large data", (progress) =>
{
Console.WriteLine($"Progress: {progress}%");
});- Event Arguments: Use custom event args classes for complex data
- Exception Handling: Handle exceptions in event handlers gracefully
- Memory Management: Unsubscribe from events when no longer needed
- Thread Safety: Consider thread safety for event handlers
- Event Frequency: Be cautious with high-frequency events
- Data Size: Keep event arguments small and serializable
- Batch Updates: Aggregate frequent small updates into batches
- Subscription Management: Limit the number of event subscriptions
// Safe event handling
myService.SomeEvent += (sender, args) =>
{
try
{
// Handle event
ProcessEventData(args);
}
catch (Exception ex)
{
// Log error but don't throw back to server
logger.LogError(ex, "Event handler failed");
}
};- CoreRemoting - Core client and server classes
- CoreRemoting.RpcMessaging - Message framework
- CoreRemoting.DependencyInjection - Service registration
- Events and Callbacks - Event concepts