Gets the object to be used for synchronized access to the jobs collections.
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 method).
Note Smtp class methods which can modify jobs collections (AddJob, 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.
[C#] lock (mailer.JobsSyncRoot) { foreach (SendMailJob job in (mailer.JobsFailed) { Console.WriteLine(job.Tag); } }
[Visual Basic] SyncLock mailer.JobsSyncRoot For Each job As SendMailJob In mailer.JobsFailed Console.WriteLine(job.Tag) Next End SyncLock
Smtp Class | MailBee.SmtpMail Namespace