EnableEvents Property
Enables or disables MailBee's ability to process
Windows events and fire its own events during operations.
When EnableEvents property is set to True, MailBee allows your application
to be responsive while MailBee is performing long-run operation (this is called
"Async mode"). Also, MailBee can fire several types of events
notifying your application about data receiving progress, status changes, or server
alerts. This is convenient for Windows applications.
When EnableEvents property is set to False (default setting), MailBee does
not process or fire any events and operates slightly faster. This mode fits well
for server environments such as ASP.
When events are turned on, you can abort current operation by calling Abort
method of IMAP4 object. Another way to do not proceed with current operation
is to set Proceed=False in IMAP4 event handler (OnReceiveData,
OnAlert, OnStatusChange).
While events are turned on and IMAP4 object is busy with some long-run
operation, Busy property is True. This
means any call of long-run methods of this IMAP4 object will immediately
fail.
Note: To handle MailBee's events (OnReceiveData,
OnAlert, OnStatusChange) in Visual Basic, make sure MailBee's type
library is checked in "Project/References" menu and MailBee.IMAP4
object is created using "WithEvents" syntax (see sample code
below). To handle only Windows events, it's enough to set EnableEvents=True
("WithEvents" syntax is not necessarily required).
Value Type: | Boolean | |
Parameters: | None | |
Remarks: | Events are useful in event-driven environments only (such as VB, VBA, Delphi, etc). ASP pages cannot handle events |
Usage example:
Option Explicit ' Early binding and "WithEvents" syntax required for handling MailBee's events Dim WithEvents objIMAP4 As MailBee.IMAP4 Private Sub Command1_Click() Dim Envelopes As MailBee.Envelopes Set objIMAP4 = CreateObject("MailBee.IMAP4") objIMAP4.LicenseKey = "put your license key here" objIMAP4.EnableEvents = True ' Enable Async mode If objIMAP4.Connect("mailserver.com", 143, "MyName", "MyPassword") Then ' Long-run operation If objIMAP4.SelectMailbox("Inbox") Then ' Long-run operation Set Envelopes = objIMAP4.RetrieveEnvelopes(1, objIMAP4.MessageCount, False) ' Long-run operation End If objIMAP4.Disconnect ' Long-run operation End If End Sub ' Respond to MailBee's OnReceiveData event and print how many data bytes received Private Sub objIMAP4_OnReceiveData(ByVal BytesReceived As Long, Proceed As Boolean) Debug.Print BytesReceived & " bytes received"
End Sub Private Sub Form_Load() Set objIMAP4 = Nothing End Sub Private Sub Form_Unload(Cancel As Integer) If objIMAP4 Is Nothing Then Exit Sub If objIMAP4.Busy Then objIMAP4.Abort ' Cancel IMAP4 session on exit End Sub
See Also:
Abort Method
Busy Property
OnAlert Event
OnReceiveData Event
OnStatusChange Event
Copyright © 2002-2024, AfterLogic Corporation. All rights reserved.