How to wait for an async method to complete inside a [LispFunction] ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone,
I'm working on a .NET plugin for AutoCAD (2017+) and I'm facing an issue when calling an async method ((extractOSMImagesAsync)) from a [LispFunction].
I have a function that downloads satellite map tiles using HttpClient and displays a Windows Form circular progress bar (Modeless form) during the download. The actual download logic is asynchronous (async Task). When I call this logic from a [LispFunction], AutoCAD continues executing the rest of the code before the download finishes and before the progress form is closed.
[LispFunction("RunOSMMaps")]
public ResultBuffer RunOSMMaps(ResultBuffer resBuf)
{
Point3d vpll = ...; // parsed from resBuf
Point3d vpur = ...;
// Other parameters like image path, zoom, etc.
ExtractImages runmaps = new ExtractImages();
if (CheckNet())
{
// This is an async Task method
runmaps.extractOSMImagesAsync(vpll, vpur, ...); // <-- returns immediately
}
// This message box is shown immediately before download completes
Application.ShowAlertDialog(" Download completed!");
return null;
}
While in this Command Method it works correct, it means "Alert dialog" shows after complete downloading process : (It should be done by LispFunction)
[CommandMethod("RunOSMMaps")]
public async void RunOSMMapsCommand()
{
Point3d vpll = ...; // parsed from resBuf
Point3d vpur = ...;
if (CheckNet())
{
// This is an async Task method
await runmaps.extractOSMImagesAsync(vpll, vpur...);
);
}
Application.ShowAlertDialog(" Download completed!");
}
Any suggestions or examples are appreciated!
Thanks in advance,