SmtpJobsSyncRoot Property
Gets the object to be used for synchronized access to the jobs collections.

Namespace: MailBee.SmtpMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.4 build 677 for .NET 4.5
public Object JobsSyncRoot { get; }

Property Value

Type: Object
A reference to the object to be used for synchronized access to JobsPending, JobsSuccessful, and JobsFailed collections.

Synchronization of the access to the jobs collections is required if the jobs are currently being processed and the application wishes to modify or enumerate any of the jobs collections on another thread using corresponding methods of SendMailJobCollection class. Synchronization is NOT required in single-thread mode (MaxThreadCount is 1 and no asynchronous methods used) or if the component has already finished processing jobs (IsBusy is false). Synchronization, however, may be required even if MaxThreadCount is 1 but the application uses worker threads or runs jobs in asynchronous mode (with BeginSendJobs(AsyncCallback, Object) method).

Note Note
Smtp class methods which can modify jobs collections (AddJob(String, String, EmailAddressCollection), RetryFailedJobs, SendJobs, etc) take care of synchronization automatically. The developer may need to use JobsSyncRoot only when accessing job collections directly.
This code snippet enumerates JobsFailed collection in a thread-safe way. This makes it possible to safely call this code even if JobsFailed collection is modified by working threads of MailBee at the same moment. It's assumed mailer is an Smtp instance.
lock (mailer.JobsSyncRoot)
    foreach (SendMailJob job in mailer.JobsFailed)
See Also