Skip to main content

Class SendMailThread

Provides asynchronous email sending functionality using a background thread to avoid blocking the calling thread.

Namespace: Workspace.XBR.Xperiflow.Utilities.Email

Assembly: Xperiflow.dll

Declaration
public class SendMailThread

Examples​

Basic asynchronous email sending:

// Send notification email asynchronously
var recipients = new List { "user@example.com", "admin@example.com" };
var subject = "Process Completed Successfully";
var body = "Your data processing job has completed successfully.";

var emailSender = new SendMailThread(
sessionInfo,
"DefaultEmailConnection",
recipients,
subject,
body,
new List() // No attachments
);

// Start sending asynchronously
emailSender.Start();

// Continue with other operations without waiting
Console.WriteLine("Email sending started in background");

Sending email with attachments:

// Send report email with attachments
var recipients = new List { "manager@company.com" };
var subject = "Monthly Sales Report";
var body = "Please find the monthly sales report attached.";
var attachments = new List
{
@"C:\Reports\SalesReport.pdf",
@"C:\Reports\SalesData.xlsx"
};

var emailSender = new SendMailThread(
sessionInfo,
"ReportEmailConnection",
recipients,
subject,
body,
attachments
);

emailSender.Start();

Integration with workflow processing:

// Send notification after workflow completion
public void ProcessWorkflowCompleted(SessionInfo si, string workflowName, List stakeholders)
{
// Process workflow results
var results = CompleteWorkflowProcessing(workflowName);

// Send asynchronous notifications
var emailBody = $"Workflow '{workflowName}' completed successfully.\\n\\n" +
$"Results:\\n" +
$"- Records processed: {results.RecordsProcessed}\\n" +
$"- Completion time: {results.CompletionTime}\\n" +
$"- Status: {results.Status}";

var emailSender = new SendMailThread(
si,
"WorkflowEmailConnection",
stakeholders,
$"Workflow Completed: {workflowName}",
emailBody,
new List()
);

emailSender.Start();

// Continue with other operations immediately
ProcessNextWorkflow();
}

Remarks​

The Workspace.XBR.Xperiflow.Utilities.Email.SendMailThread class enables asynchronous email sending by wrapping the OneStream email functionality in a background thread. This is particularly useful for long-running operations where you don't want to block the calling thread waiting for email delivery.

Key Features:

  • Asynchronous OperationSends emails in a background thread without blocking the caller

  • OneStream IntegrationUses OneStream's email infrastructure with proper session context

  • Attachment SupportSupports multiple file attachments

  • Error HandlingRobust error handling with proper logging

Thread Safety:

The class is designed to be instantiated and started from the calling thread, but the actual email sending occurs on a background thread. The background thread is configured as a daemon thread to ensure it doesn't prevent application shutdown.

Error Handling:

Exceptions in the background thread are logged using OneStream's error logging system but are not propagated back to the calling thread. This prevents unhandled exceptions from crashing the application.

Methods​

Start()​

Starts the asynchronous email sending process on a background thread.

Declaration
public void Start()
Remarks​

This method creates and starts a new background thread that will send the email using the parameters provided during construction. The calling thread returns immediately without waiting for the email to be sent.

Thread Configuration:

  • The background thread is configured as a daemon thread (IsBackground = true)

  • The thread name includes a GUID for unique identification during debugging

  • The thread inherits the culture information from the current user's session

  • The thread is configured to not prevent application shutdown

Error Handling:

Exceptions during thread creation are propagated to the caller. Exceptions during email sending (on the background thread) are logged but not propagated.

Exceptions​

OneStream.Shared.Common.XFException Thrown when an error occurs during thread creation or initialization

Inherited Members​

  • System.Object.Equals(System.Object)
  • System.Object.Equals(System.Object,System.Object)
  • System.Object.GetHashCode
  • System.Object.GetType
  • System.Object.MemberwiseClone
  • System.Object.ReferenceEquals(System.Object,System.Object)
  • System.Object.ToString

Was this page helpful?