-
Notifications
You must be signed in to change notification settings - Fork 11
Functions (Client)
CheshireCaat edited this page Feb 6, 2020
·
15 revisions
If you want to run the function, and you do not need to control the lifetime of the threads, use BasRemoteClient instance for this.
There are two possible ways to start - synchronous and asynchronous. In the case of the asynchronous version, the task will be launched, which will end immediately after receiving the result or error from function. This is very convenient since you can run tasks not only sequentially, but also in parallel. Take a look at examples
using (var client = new BasRemoteClient(new Options {ScriptName = "TestRemoteControl"}))
{
await client.Start();
// Call one function and get the result.
var result = await client.RunFunction("GoogleSearch", new Params
{
{"Query", "cats"}
});
System.Console.ReadKey();
}
var task1 = client.RunFunction("GoogleSearch", new Params {{"Query", "cats"}});
var task2 = client.RunFunction("GoogleSearch", new Params {{"Query", "dogs"}});
var result = await Task.WhenAll(task1, task2);
foreach (var taskResult in result)
foreach (var link in taskResult)
Console.WriteLine(link);
try
{
var result = await client.RunFunction("NotExistingFunction", Params.Empty);
}
catch (FunctionException ex)
{
Console.WriteLine(ex.Message);
}