Skip to content

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

executeCsharp

Parameters

ParameterTypeRequiredDescription
funidstringFunction ID (returned by compileCsharp)
argsobjectParameter 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 VariableDescriptionReturn TypeUsage Example
$.screenshot(deviceId)Get real-time screenshot of specified devicebyte[]"$.screenshot('P72578581E07')"

Notes

⚠️ Important Notes

  1. 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
  2. funid Validity

    • funid is valid during application runtime
    • Needs to be recompiled after application restart
  3. Parameter Type Matching

    • Parameter types must match types in C#
    • Pay attention to numeric type precision issues
  4. Memory Management

    • Promptly release unmanaged resources in C#, release related resources after task processing
    • Fatal code defects may cause iClick to crash

Cooperation: try.catch@foxmail.com