Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(DataFlex) Understanding Async Function Return ValuesSee more Async ExamplesExplains how to get the return value of the function called synchonously in the background thread.
Use ChilkatAx-win32.pkg Procedure Test Handle hoSock Boolean iSuccess Variant vTask Handle hoTask Integer iCount String s Variant vConnection Handle hoConnection Handle hoAcceptedConnection Boolean bTemp1 // Some Chilkat functions can be called asynchronously. // If a function "Func" can be called asynchronously, there will be a corresponding "FuncAsync" function that returns a Task object. // // When Task.Run is called, the synchronous "Func" runs in a background thread. // // For Chilkat methods that return a status (True/False), get returned value by calling GetResultBool. // For example.. Get Create (RefClass(cComChilkatSocket)) To hoSock If (Not(IsComObjectCreated(hoSock))) Begin Send CreateComObject of hoSock End // -------------------------------------------------------------- // Synchronous call returning True/False Get ComConnect Of hoSock "example.com" 443 True 5000 To iSuccess // -------------------------------------------------------------- // Asynchronous call Get ComConnectAsync Of hoSock "example.com" 443 True 5000 To vTask If (IsComObject(vTask)) Begin Get Create (RefClass(cComChilkatTask)) To hoTask Set pvComObject Of hoTask To vTask End // ... Get ComRun Of hoTask To iSuccess // ... // ... // Get the status (True/False) value returned by the synchronous method called in the background thread. Get ComGetResultBool Of hoTask To iSuccess // -------------------------------------------------------------- // Synchronous call returning an integer Get ComReceiveCount Of hoSock To iCount // -------------------------------------------------------------- // Asynchronous call Get ComReceiveCountAsync Of hoSock To vTask If (IsComObject(vTask)) Begin Get Create (RefClass(cComChilkatTask)) To hoTask Set pvComObject Of hoTask To vTask End // ... Get ComRun Of hoTask To iSuccess // ... // ... // Get the integer value returned by the synchronous method called in the background thread. Get ComGetResultInt Of hoTask To iCount // -------------------------------------------------------------- // Synchronous call returning an string Get ComReceiveString Of hoSock To s // -------------------------------------------------------------- // Asynchronous call Get ComReceiveStringAsync Of hoSock To vTask If (IsComObject(vTask)) Begin Get Create (RefClass(cComChilkatTask)) To hoTask Set pvComObject Of hoTask To vTask End // ... Get ComRun Of hoTask To iSuccess // ... // ... // Get the string value returned by the synchronous method called in the background thread. Get ComGetResultString Of hoTask To s // -------------------------------------------------------------- // Synchronous call returning an object Get ComAcceptNextConnection Of hoSock 5000 To vConnection If (IsComObject(vConnection)) Begin Get Create (RefClass(cComChilkatSocket)) To hoConnection Set pvComObject Of hoConnection To vConnection End // -------------------------------------------------------------- // Asynchronous call Get ComAcceptNextConnectionAsync Of hoSock To vTask If (IsComObject(vTask)) Begin Get Create (RefClass(cComChilkatTask)) To hoTask Set pvComObject Of hoTask To vTask End // ... Get ComRun Of hoTask To iSuccess // ... // ... // Get the object returned by the synchronous method called in the background thread. // We do this a little differently. We create an new object of the same type, // and then load it with the returned object (assuming it was not null). Get Create (RefClass(cComChilkatSocket)) To hoAcceptedConnection If (Not(IsComObjectCreated(hoAcceptedConnection))) Begin Send CreateComObject of hoAcceptedConnection End Get ComTaskSuccess Of hoTask To bTemp1 If (bTemp1 = True) Begin Get ComLoadTaskResult Of hoAcceptedConnection vTask To iSuccess End End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.