This topic is locked

Using Async calls when calling a custom class

5/17/2025 12:34:04 PM
ASPRunner.NET General questions
P
precisiondi author

In my project I have a custom button that interects with a custom method has anybody been able to use asyc calls in this type of setup?

I have only been able to make it work using wait().

Example:
Task<DocEdit.NewTemplate> returnValueTask = DocEdit.EditMergeTemplate(Url, apiKey, templateId, templateName, jsonObject.ToString(Newtonsoft.Json.Formatting.Indented), fileInfo, TableName);
returnValueTask.Wait();
var returnValue = returnValueTask.Result;

if (returnValue != null && returnValue.DocumentUrl != null)
{
// Perform actions based on returned values
string documentUrl = returnValue.DocumentUrl;
Log("Document URL: " + documentUrl);

// Update the database
string editUrlsql = DB.PrepareSQL($"UPDATE {TableName} SET Url = ':1' WHERE DocumentId = ':2'", documentUrl, docId);
DB.Exec(editUrlsql);

editUrl = documentUrl;
}

But I would like to format it like:

await DocEdit.EditMergeTemplate

instead of having to use:

returnValueTask.Wait();

The custom method was inspired from this post:

https://asprunner.com/forums/topic/23911-write-your-own-custom-functions/