0

I have a method that uses an client SDK (sensenet) to make requests Sensenet.

private static async Task CreateFolder(String parentPath, String folderName)
    {

        SensenetRepository.WriteLog(typeof(SensenetRepository).Name, "Init CreateFolder: " + parentPath + "/" + folderName);

        var folder = Content.CreateNew(parentPath, "Folder", folderName);
        await folder.SaveAsync();

    }

I have to integrate this on my current api that is fully synchronous. (Do it all asynchronous will require a big changes on the clients and on the structure of the project)

To run "CreateFolder" synchronous, I'm calling like this:

CreateFolder(pathEntity, fileDate).Wait(); //seems to not stop here
//more code to execute after createFolder...

On CreateFolder execution it seems that is running asynchronous despite having Wait() calling.

I'm having difficult to call CreateNew method from Sensenet Client, since the save is always "SaveAsync".

  • CreateFolder("","").GetAwaiter().GetResult(); – Karolis Kajenas May 15 '17 at 11:51
  • 1
    the code shown with `.Wait()` is *far from perfect* ("sync over async"), but it should *work* OK (as long as sync-context isn't part of things). What makes you think it is wrong? You say "seems to not stop here" - but: are you sure it hasn't just *finished*? – Marc Gravell May 15 '17 at 11:54
  • In this case I don't have that action available. "await folder.SaveAsync();" does not return anything... – Luciano Valinho May 15 '17 at 11:55
  • 3
    Depending on the context, this might cause deadlocks... – grek40 May 15 '17 at 11:55
  • btw: `CreateFolder` doesn't really need to be `async` - it *looks* like you could simply remove the `async` modifier and chage the last line to `return folder.SaveAsync();` – Marc Gravell May 15 '17 at 11:56
  • I tried that, but doesn't work. Same issue. – Luciano Valinho May 15 '17 at 14:35
  • Can you describe how you decided that it is still running async despite your `Wait` call? What happens that makes you think it's not synchronized? – grek40 May 16 '17 at 06:40

0 Answers0