private static void TaskCompleted(Task <object> task, object state) { DebugMessage("CoreCLREmbedding::TaskCompleted (CLR) - Task completed with a state of {0}", task.Status.ToString("G")); DebugMessage("CoreCLREmbedding::TaskCompleted (CLR) - Marshalling data to return to V8", task.Status.ToString("G")); V8Type v8Type; TaskState actualState = (TaskState)state; IntPtr resultObject; TaskStatus taskStatus; if (task.IsFaulted) { taskStatus = TaskStatus.Faulted; try { resultObject = MarshalCLRToV8(task.Exception, out v8Type); } catch (Exception e) { taskStatus = TaskStatus.Faulted; resultObject = MarshalCLRToV8(e, out v8Type); } } else { taskStatus = TaskStatus.RanToCompletion; try { resultObject = MarshalCLRToV8(task.Result, out v8Type); } catch (Exception e) { taskStatus = TaskStatus.Faulted; resultObject = MarshalCLRToV8(e, out v8Type); } } DebugMessage("CoreCLREmbedding::TaskCompleted (CLR) - Invoking unmanaged callback"); actualState.Callback(resultObject, (int)v8Type, (int)taskStatus, actualState.Context); }