SerializationException nel spedire Mail

giovedì 04 gennaio 2007 - 00.06

paroca Profilo | Newbie

Ciao a tutti,

ho un problema che mi stà facendo impazzire..
Ho creato una coda per il sending di parecchie mail ed un thread che ne spedisce una ogni 5 secondi..
La coda è protetta da un mutex..
La mail vengono gestite con MailMessage e SmtpMail..
Tutto a posto se non che quando arrivo al SmtpMail.Send mi scatta una SerializationException in un modulo sconosciuto..

Qualcuno sa aiutarmi???
Grazie in anticipo

vi allego il codice qui di seguito:

Imports System
Imports System.Threading
Imports System.Web.Mail

Public Class MailSender

Private Class MailStructure
Public Body As String
Public From As String
Public [To] As String
Public Subject As String
Public HTML As Boolean
Public SMTP As String
End Class

Private Shared _IsRunning As Boolean = False
Private Shared _HL As Queue = New Queue
Private Shared _Mutex As Mutex = New Mutex
Private Shared _Timeout As Long = 5000

Public Shared Sub InsertInSendList(ByVal From As String, ByVal [To] As String, ByVal Subject As String, _
ByVal Body As String, ByVal SMTP As String)
Dim MS As MailStructure = New MailStructure
MS.From = From
MS.To = [To]
MS.Subject = Subject
MS.Body = Body
MS.SMTP = SMTP
MS.HTML = True

_Mutex.WaitOne()
_HL.Enqueue(MS)
_Mutex.ReleaseMutex()
End Sub

Private Shared Sub MyThreadProc()
_IsRunning = True
While _HL.Count > 0
_Mutex.WaitOne()
Dim MS As MailStructure = _HL.Dequeue
_Mutex.ReleaseMutex()

SendMail(MS.From, MS.To, MS.Subject, MS.Body, MS.SMTP, MS.HTML)
Thread.Sleep(_Timeout)
End While
_IsRunning = False
End Sub

Public Shared Sub SendMail(ByVal From As String, ByVal [To] As String, ByVal Subject As String, _
ByVal Body As String, ByVal SMTP As String, Optional ByVal HTML As Boolean = False)
Dim mail As New MailMessage
mail.From = From
mail.To = [To]
mail.Subject = Subject
mail.Body = Body
If HTML Then mail.BodyFormat = MailFormat.Html Else mail.BodyFormat = MailFormat.Text

SmtpMail.SmtpServer = SMTP
SmtpMail.Send(mail)
End Sub

Public Shared Sub Send()
If Not _IsRunning Then
Dim myThread As New Thread(AddressOf MyThreadProc)
myThread.Start()
End If
End Sub

End Class
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2023
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5