I appolgize if this is not the correct forum for this question. As the issue came up working with the APIs here, I figured I would start here and go elsewhere if necessary.
I'm using the latest .NET dropbox.api library on VS 2019. I have been asked to create a in-house library for other developers to use until we can put together some in-house formal training for everyone on Dropbox's APIs. I've read through the documentation and the sample GitHub code. I reproduced the example and got it working. Everything's good. The working code (abridged for brevity):
static void Main(string[] args) {
var task = Task.Run((Func<Task>)Program.Run);
task.Wait();
}
static async Task Run() {
using (var dbx = new DropboxClient("MyAccessToken")) {
await CreateFolder(dbx, "/2019-11-07");
Console.ReadKey();
}
}So I move on to starting to build a basic library and will add all the bells and whistles after getting a few functions to work. This is where the problem is. I created what I thought was a similar entry point but now I'm getting a compiler error The erroring code:
public int CreateFolder(string strPath, string FileName) {
try {
var task = Task.Run((Func<Task>)SoDropbox.CF(Path.Combine(strPath,FileName)));
task.Wait();
}
catch(Exception e) {
return -1;
}
return 1;
}
static async Task CF(string strPath) {
using (var dbx = client) {
var folderArg = new CreateFolderArg(Path);
var folder = await dbx.Files.CreateFolderV2Async(folderArg);
}
}The error that I am getting is in the first line of the try block or the CreateFolder method. The error is: Cannot convert type 'System.Threading.Tasks.Task' to 'System.Func<System.Threading.Tasks.Task>'
I'm sure this has more to do with my lack of understanding of the Func delegate and asynchronous Tasks but I am not seeing what the difference is between the working code and the new code.
Any help would be appreciated and, like I said, if this is not appropriate for this forum just let me know.