wwDotNetBridge.InvokeTaskMethodAsync

This method allows you to call any .NET async method - any method that returns a Task object basically - asynchronously by passing in a callback object that is called back when the async method completes or fails.

o.wwDotNetBridge.InvokeTaskMethodAsync(loCallback, loInstance, loMethod)

Parameters

loCallback
A callback object that inherits from AsyncCallbackEvents and implements� OnCompleted(lvResult, lcMethod) and OnError(lcMessage, loException, lcMethod) methods that are called when the async method call completes or fails.

loInstance
The object on which the async method is called

loMethod
The method that is to be called as a string

lvParm1..lvParm10
Up to 10 parameters that can be passed to the method.

Example

* This sample demonstrates running 2 HTTP requests simultaneously
CLEAR
do wwDotNetBridge
LOCAL loBridge as wwDotNetBridge
loBridge = CreateObject("wwDotNetBridge","V4")

loClient = loBridge.CreateInstance("System.Net.WebClient")

* Optional - go through Fiddler Proxy
*loClient.Proxy = loBridge.CreateInstance("System.Net.WebProxy","http://127.0.0.1:8888",.F.)

loCallback = CREATEOBJECT("HttpCallback")

*** HTTP GET

*** execute and returns immediately
loTask = loBridge.InvokeTaskMethodAsync(loCallback, loClient,"DownloadStringTaskAsync","https://west-wind.com/wconnect/TestPage.wwd")
? loTask  && object

? "Mainline Done..."


*** HTTP POST

loClient2 = loBridge.CreateInstance("System.Net.WebClient")

lcPost = "LastName=Strahl&FirstName=Rick&Company=West+Wind+Technologies"
loBridge.InvokeMethod(loClient2,"Headers.Add","Content-Type","application/x-www-form-urlencoded")
? loBridge.cErrORMSG
loTask = loBridge.InvokeTaskMethodAsync(loCallback, loClient2,"UploadDataTaskAsync","https://west-wind.com/wconnect/TestPage.wwd",CAST(lcPost as BLOB))

? "Mainline Done..."

RETURN


DEFINE CLASS HttpCallback as AsyncCallbackEvents

*** Returns the result of the method and the name of the method name
FUNCTION OnCompleted(lvResult,lcMethod)

? "File received. Size: " + TRANSFORM(LEN(lvResult))
? SUBSTR(lvResult,1,1000)

*** Convert binary data to string (optional)
IF VARTYPE(lvResult) = "Q"
   lvResult = CAST( lvResult as M)
ENDIF

*ShowHtml(lvResult)

ENDFUNC


* Returns an error message, a .NET Exception and the method name
FUNCTION OnError(lcMessage,loException,lcMethod)
? "Error: " + lcMethod,lcMessage
ENDFUNC

ENDDEFINE

See also:

Class wwDotNetBridge

© West Wind Technologies, 1996-2024 • Updated: 04/20/23
Comment or report problem with topic