Cancels the current operation.
public void Cancel()
Public Sub Cancel
public:
void Cancel();
Shows how to use the Cancel method to cancel the current operation.
using System;
using ComponentPro.Net.Mail;
...
public void DoAbort()
{
// Create a new Imap instance.
Imap client = new Imap();
// Connect to the IMAP server.
client.Connect("myserver");
// Authenticate.
client.Authenticate("test", "test");
try
{
// Register an event handler.
client.Progress += client_Progress;
client.Select("INBOX");
// Download a message with sequence number #1.
client.DownloadMessage(1, "c:\\temp\\my message.eml");
}
catch (ImapException exc)
{
Console.WriteLine("Exception: " + exc.Message);
}
// Disconnect.
client.Disconnect();
}
void client_Progress(object sender, ImapProgressEventArgs e)
{
// Abort the download operation if the bytes transferred is greater than or equal to 500Kb.
if (e.State == ImapTransferState.Downloading && e.BytesTransferred >= 1024 * 500)
{
((Imap)sender).Cancel();
}
}
Imports ComponentPro.Net.Mail
...
Public Sub DoAbort()
' Create a new Imap instance.
Dim client As New Imap()
' Connect to the IMAP server.
client.Connect("myserver")
' Authenticate.
client.Authenticate("test", "test")
Try
' Register an event handler.
AddHandler client.Progress, AddressOf client_Progress
client.Select("INBOX")
' Download a message with sequence number #1.
client.DownloadMessage(1, "c:\temp\my message.eml")
Catch exc As ImapException
Console.WriteLine("Exception: " & exc.Message)
End Try
' Disconnect.
client.Disconnect()
End Sub
Private Sub client_Progress(ByVal sender As Object, ByVal e As ImapProgressEventArgs)
' Abort the download operation if the bytes transferred is greater than or equal to 500Kb.
If e.State = ImapTransferState.Downloading AndAlso e.BytesTransferred >= 1024 * 500 Then
CType(sender, Imap).Cancel()
End If
End Sub