// UploadCreate is the worksheet function // It reads the caller, which we need to track for the UploadSelection option, // gathers all the arguments and then starts the RTD tracking with a call to ExcelAsyncUtil.Observe. // // There can be many more arguments // We might experiment with AllowReference=true for the arguments // That could improve performance a lot // But there are concerns: // * Does Upload get called whenever the contents of the reference change? // * We need care when we read it (at the Upload-time) public static object UploadCreate(object arg1, object arg2, object arg3) { var caller = XlCall.Excel(XlCall.xlfCaller) as ExcelReference; // Might be null if called in unusual context, e.g. Application.Run var topicFunctionName = nameof(UploadCreate); var topicArguments = new object[] { caller, arg1, arg2, arg3 }; // Adding the caller here is important since we need to track it for the RTD topic too return(ExcelAsyncUtil.Observe(topicFunctionName, topicArguments, () => UploadManager.CreateItem(topicArguments))); }