Grasshopper

algorithmic modeling for Rhino

C# trying to use async Task request to POST to rest API - task never run

Dear all,

I am trying to send files to a server using an async await Task paradigm, but it appears that when C# attempts to execute this task the task is never completed.

I've tried to pull the async part of the code out of the main event loop,  using a well-known design pattern, where all async code is in its own library, and when I call the async code, I do something like this:

main loop

   doSomeAsyncStuff().Wait()

end main loop

This pattern is often used when running async code in console apps, for example where async code cannot be executed.  

So I'm not sure why this is not working.  Is there something within Grasshopper which will not allow sync Tasks to run?  I'd assume that others have hit API's inside of Grasshopper before using C#.  How can I work around this issue?

For what it is worth, I am using the NuGet package RestSharp.

Many thanks!

Views: 871

Replies to This Discussion

So I'm not sure why this is not working.  Is there something within Grasshopper which will not allow sync Tasks to run?

No, there's nothing special about C# inside GH. I just compile the code using the standard C# compiler and then execute it using the standard runtime. As long as the .NET version running GH understands the C# constructs, it should run. If not, you should be getting comprehensive error messages.

It's not a problem that the method you're running this code from needs to be decorated as async right?

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service