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
(AutoIt) Async Methods Returning an ObjectDemonstrates how to call an asynchronous method that returns an object. This example reads email from a POP3 server using the Async versions of the Chilkat methods.
; All Chilkat classes can be unlocked at once at the beginning of a program ; by calling UnlockBundle. It requires a Bundle unlock code. $oChilkatGlob = ObjCreate("Chilkat.Global") Local $bSuccess = $oChilkatGlob.UnlockBundle("Anything for 30-day trial.") If ($bSuccess <> True) Then ConsoleWrite($oChilkatGlob.LastErrorText & @CRLF) Exit EndIf $oMailman = ObjCreate("Chilkat.MailMan") ; Set the POP3 server's hostname $oMailman.MailHost = "pop.someMailServer.com" ; Set the POP3 login/password and any other requirements.. $oMailman.PopUsername = "myLogin" $oMailman.PopPassword = "myPassword" $oMailman.PopSsl = True $oMailman.MailPort = 995 ; Connect to the POP3 server: Local $oTask = $oMailman.Pop3BeginSessionAsync() If ($oMailman.LastMethodSuccess = False) Then ConsoleWrite($oMailman.LastErrorText & @CRLF) Exit EndIf ; Start the background task. $bSuccess = $oTask.Run() If (Not $bSuccess) Then ConsoleWrite($oTask.LastErrorText & @CRLF) Exit EndIf ; Wait for the POP3 connect task to finish. ; The True/False returned by Wait applies to the Wait method call, not the task. Local $iMaxWaitMs = 30000 $bSuccess = $oTask.Wait($iMaxWaitMs) If (Not $bSuccess Or ($oTask.StatusInt <> 7) Or ($oTask.TaskSuccess <> True)) Then If (Not $bSuccess) Then ; The task.LastErrorText applies to the Wait method call. ConsoleWrite($oTask.LastErrorText & @CRLF) Else ; The ResultErrorText applies to the underlying task method call (i.e. the Pop3BeginSession) ConsoleWrite($oTask.Status & @CRLF) ConsoleWrite($oTask.ResultErrorText & @CRLF) EndIf Exit EndIf ; Get the number of messages in the mailbox. $oTask = $oMailman.GetMailboxCountAsync() ; To keep the example short, we'll skip handling failures. ; The failures would be handled in the same way as shown above. $bSuccess = $oTask.Run() $bSuccess = $oTask.Wait($iMaxWaitMs) Local $iNumMessages = $oTask.GetResultInt() If ($iNumMessages = 0) Then Exit EndIf $oEmail = ObjCreate("Chilkat.Email") Local $i For $i = 1 To $iNumMessages $oTask = $oMailman.FetchByMsgnumAsync($i) If ($oMailman.LastMethodSuccess = False) Then ConsoleWrite($oMailman.LastErrorText & @CRLF) Exit EndIf $bSuccess = $oTask.Run() $bSuccess = $oTask.Wait($iMaxWaitMs) If (Not $bSuccess Or ($oTask.StatusInt <> 7) Or ($oTask.TaskSuccess <> True)) Then If (Not $bSuccess) Then ; The task.LastErrorText applies to the Wait method call. ConsoleWrite($oTask.LastErrorText & @CRLF) Else ; The ResultErrorText applies to the underlying task method call (i.e. the FetchByMsgnum) ConsoleWrite($oTask.Status & @CRLF) ConsoleWrite($oTask.ResultErrorText & @CRLF) EndIf Exit EndIf ; Each Chilkat object that can be a return value of an asynchronous task will ; have a method named LoadTaskResult. The object returned in the underlying ; asynchronous method call is retrieved by calling LoadTaskResult. ; To say it another way: The application will provide a pre-existing object of ; the desired return type (in this case it is an email object). This object is ; loaded by calling LoadTaskResult. $bSuccess = $oEmail.LoadTaskResult($oTask) If (Not $bSuccess) Then ConsoleWrite($oEmail.LastErrorText & @CRLF) Exit Else ConsoleWrite($oEmail.From & ": " & $oEmail.Subject & @LF & @CRLF) EndIf Next |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.