I am working on a wrapper library for a robot controller that relies heavily on P / Invoke calls.
However, many functions for the robot, such as homing or moving objects, take a lot of time and perform thread blocking during operation.
So, I am wondering how I can wrap functionality in an asynchronous way, so calls do not block my UI thread. My idea so far is to use Tasks, but I'm not sure if this is the right approach.
public Task<bool> HomeAsync(Axis axis, CancellationToken token) { return Task.Factory.StartNew(() => Home(axis), token); }
Most MSDN articles in the Async model in .NET at the moment are mainly relayed to libraries that already have Async features (such as File.BeginRead, etc.). But I can not find much information on how to actually write asynchronous functions in the first place.
c #
Claus jørgensen
source share