-
Notifications
You must be signed in to change notification settings - Fork 12
Functions (Threads)
Running functions through threads is very similar to a regular launch through BasRemoteClient
. The main feature of this type of launch is that you can control the launch yourself, stop the thread, and check whether it is busy with the execution of functions. This is very convenient cause it gives you complete control over the execution of functions.
If you want to create new thread then use client.CreateThread()
method. This method returns IBasThread
interface, that contains several useful methods and properties. Take a look at example.
var thread = client.CreateThread();
// Set up proxy.
await thread.RunFunction("SetProxy", new Params
{
{"Proxy", "127.0.0.1:11185"},
{"IsSocks5", "true"}
}).GetTask();
// Check the ip of this proxy.
var proxyIp = await thread.RunFunction("CheckIp", Params.Empty).GetTask();
// Stop the thread.
thread.Stop();
Obviously, starting threads manually and calling functions through client is very similar. But in the case of a manual start, you can, for example, wait for the thread to finish working using IsRunning
property.
// Run function without await.
thread.RunFunction("SomeFunction", Params.Empty);
// Wait until function complete.
while (thread.IsRunning)
{
await Task.Delay(TimeSpan.FromSeconds(10));
}