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
(PureBasic) Get the LastErrorText for an Asynchronous Method CallSee more Async ExamplesDemonstrates how to get the LastErrorText information for a Chilkat method called asynchronously.
IncludeFile "CkSocket.pb" IncludeFile "CkTask.pb" Procedure ChilkatExample() ; This example requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. socket.i = CkSocket::ckCreate() If socket.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; The Async call simply creates the task. The "Connect" method has not yet been called. maxWaitMs.i = 5000 ; Let's intentionally cause this connect to fail by giving it an invalid domain.. task.i = CkSocket::ckConnectAsync(socket,"amazonbladflakjsdflksadjf.com",443,1,maxWaitMs) If CkSocket::ckLastMethodSuccess(socket) = 0 Debug CkSocket::ckLastErrorText(socket) CkSocket::ckDispose(socket) ProcedureReturn EndIf ; Start the background thread to run the task. success.i = CkTask::ckRun(task) If Not success Debug CkTask::ckLastErrorText(task) CkTask::ckDispose(task) CkSocket::ckDispose(socket) ProcedureReturn EndIf ; The application is now free to do anything else ; For this example, we'll simply sleep and periodically ; check to see if the Socket Connect if finished. While CkTask::ckFinished(task) <> 1 ; Sleep 1 ms. CkTask::ckSleepMs(task,1) Wend ; If the task completed, it means the method (in this case the Connect method) was called and returned success or failure. If CkTask::ckStatusInt(task) <> 7 Debug "Task did not complete." Debug "task status: " + CkTask::ckStatus(task) CkTask::ckDispose(task) CkSocket::ckDispose(socket) ProcedureReturn EndIf ; Get the success/failure of the Connect ; (This is the return value of the Connect method had it been called synchronously) success = CkTask::ckGetResultBool(task) If success = 0 ; Get the LastErrorText for the Connect method call. ; Had we called Connect synchronously, we would've simply accessed the socket object's LastErrorText property. ; Instead, we get the task object's ResultErrorText. Debug CkTask::ckResultErrorText(task) Else Debug "Connect succeeded." EndIf CkTask::ckDispose(task) CkSocket::ckDispose(socket) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.