We recommend using Visual Studio 2017

Context.CheckCancelled Method

Throws an exception if the query has timed out or been canceled by the user.

Namespace:  Microsoft.AnalysisServices.AdomdServer
Assembly:  msmgdsrv (in msmgdsrv.dll)

public static void CheckCancelled()

The exception raised by CheckCancelled should be handled, and then rethrown.

In the following example, a UDF is defined that takes a very long time to execute. Occasionally, it calls CheckCancelled to determine if the function should exit:

public string LongRunning()

        //Enter a long running loop
        for (int nIndex = 0; nIndex < 1000; nIndex++)
            //Exception generated when the query is canceled or Timeout occurs
    catch (System.Exception ex)
        throw ex;

    return "UDF Allowed to Finish";