Task Parallel Library & CUDA ErrorInvalidContext is shown???


I am using CUDAfy to use CUDA along with C#. In order to keep the GUI responsive I am trying to use the TPL.

Whenever a CUDA Command occurs in the code I get this Error: “CUDA.NET exception: ErrorInvalidContext”.

I have absolutely no clue what to do, since I just began working with the TPL :(

Hopefully somebody can help.

Thank you

var uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();

CancellationTokenSource tokenSource = new CancellationTokenSource();

CancellationToken cancellationToken = tokenSource.Token;

SynchronizationContext synContext = SynchronizationContext.Current;

Task customerTask = Task.Factory.StartNew(() =>



double[] dev_yp = gpu.Allocate<double>(new double[4]);