Execute C# Function
The executeCsharp interface is used to execute C# functions that have been compiled and registered through compileCsharp.
⏱️ Cold Start Time
First execution will have 50-200 milliseconds of cold start time, subsequent calls have no overhead.
Interface Description
Interface Type
executeCsharpParameters
| Parameter | Type | Required | Description |
|---|---|---|---|
funid | string | ✅ | Function ID (returned by compileCsharp) |
args | object | ❌ | Parameter object passed to C# function |
Return Value
Returns the execution result of the C# function, type depends on the C# function's return value.
Basic Usage
Complete Flow Example
javascript
// 1. Function ID obtained from compilation
const funid = 'XXXXX';
// 2. Execute function
const result = await apiInvoke("executeCsharp", {
funid: funid,
args: {
inta: 10,
floatb: 18.8,
// Can reference magic parameter variables
screenshot: "$.screenshot('deviceId')"
}
});
console.log('Execution result:', result);Magic Parameter Variables
iClick provides special magic variables that can dynamically obtain system data during calls. Magic variables start with $. and are automatically parsed to actual data before execution.
Available Magic Variables
| Magic Variable | Description | Return Type | Usage Example |
|---|---|---|---|
$.screenshot(deviceId) | Get real-time screenshot of specified device | byte[] | "$.screenshot('P72578581E07')" |
Notes
⚠️ Important Notes
Magic Variable Usage Rules
- Magic variables must be passed as strings (e.g.,
"$.screenshot('id')") - Magic variables are automatically parsed to actual data before execution
- Magic variables must be passed as strings (e.g.,
funid Validity
- funid is valid during application runtime
- Needs to be recompiled after application restart
Parameter Type Matching
- Parameter types must match types in C#
- Pay attention to numeric type precision issues
Memory Management
- Promptly release unmanaged resources in C#, release related resources after task processing
- Fatal code defects may cause iClick to crash