|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Unique GUID for an asynchronous taskhandler that gets trigerred when the task is completed. One of the arguments of the event handler has a method UserState; UserState gets a unique GUID for the asynchronous task. How do I get this GUID when (or before) I send the mail? I'd like to record the GUID in a database table and then from the event handler, update the row with the outcome reported by the argument e. Thanks. SmtpClient client = new SmtpClient(mailClient); client.SendCompleted += new SendCompletedEventHandler(MailDeliveryComplete); public void MailDeliveryComplete(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { LogMessage("Message token = " + e.UserState); } More complete code of the context is found here
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx Show quoteHide quote "AA2e72E" wrote: > I am using System.Net.Mail to send mail asynchronously. I have an event > handler that gets trigerred when the task is completed. > > One of the arguments of the event handler has a method UserState; UserState > gets a unique GUID for the asynchronous task. > > How do I get this GUID when (or before) I send the mail? I'd like to record > the GUID in a database table and then from the event handler, update the row > with the outcome reported by the argument e. > > Thanks. > > SmtpClient client = new SmtpClient(mailClient); > > client.SendCompleted += new SendCompletedEventHandler(MailDeliveryComplete); > > public void MailDeliveryComplete(object sender, > System.ComponentModel.AsyncCompletedEventArgs e) > { > LogMessage("Message token = " + e.UserState); > > > } > >
Show quote
Hide quote
"AA2e72E" <AA2e***@discussions.microsoft.com> wrote in message Assuming you're using the SendAsync() method, you pass this information in news:1CA5C82E-F25C-4783-AC2A-61D972856704@microsoft.com... >I am using System.Net.Mail to send mail asynchronously. I have an event > handler that gets trigerred when the task is completed. > > One of the arguments of the event handler has a method UserState; > UserState > gets a unique GUID for the asynchronous task. > > How do I get this GUID when (or before) I send the mail? I'd like to > record > the GUID in a database table and then from the event handler, update the > row > with the outcome reported by the argument e. > > Thanks. > > SmtpClient client = new SmtpClient(mailClient); > > client.SendCompleted += new > SendCompletedEventHandler(MailDeliveryComplete); > > public void MailDeliveryComplete(object sender, > System.ComponentModel.AsyncCompletedEventArgs e) > { > LogMessage("Message token = " + e.UserState); > > > } the userToken parameter. If you need to pass more than one piece of information, create a class and add your various items as properties, then pass the class. In the event handler, you cast the UserState property back into your class object. Thanks for the response Jeff. I think I understand (most) of what you are
saying: - I am using SendAsync; userToken is the second argument of SendAsync. - I understand about creating a class and adding multiple properties - I understand about passsing the class as the userToken argument. However, I am not totally clear about "In the event handler, you cast the UserState property back into your class object. " I guess you might mean the following: have one of the properties of the class such that it uniquely identifies the message being sent and then use the same property to update the row in the database. Casting the UserState: myClass mailid = (myClass) e.UserState; Then ,mailid.myproperty will return me what I passed? I suppose I can try out the code. But, if I have completely misunderstood, please enlighten me ... with some code snippets (?). Thanks. Show quoteHide quote "Jeff Johnson" wrote: > "AA2e72E" <AA2e***@discussions.microsoft.com> wrote in message > news:1CA5C82E-F25C-4783-AC2A-61D972856704@microsoft.com... > > >I am using System.Net.Mail to send mail asynchronously. I have an event > > handler that gets trigerred when the task is completed. > > > > One of the arguments of the event handler has a method UserState; > > UserState > > gets a unique GUID for the asynchronous task. > > > > How do I get this GUID when (or before) I send the mail? I'd like to > > record > > the GUID in a database table and then from the event handler, update the > > row > > with the outcome reported by the argument e. > > > > Thanks. > > > > SmtpClient client = new SmtpClient(mailClient); > > > > client.SendCompleted += new > > SendCompletedEventHandler(MailDeliveryComplete); > > > > public void MailDeliveryComplete(object sender, > > System.ComponentModel.AsyncCompletedEventArgs e) > > { > > LogMessage("Message token = " + e.UserState); > > > > > > } > > Assuming you're using the SendAsync() method, you pass this information in > the userToken parameter. If you need to pass more than one piece of > information, create a class and add your various items as properties, then > pass the class. In the event handler, you cast the UserState property back > into your class object. > > >
Show quote
Hide quote
"AA2e72E" <AA2e***@discussions.microsoft.com> wrote in message You've already discovered the answer, but for posterity: You understood news:2A31E4B0-7C1F-4F3C-80B6-F4DAEB5E27D5@microsoft.com... > However, I am not totally clear about "In the event handler, you cast the > UserState property back into your class object. " I guess you might mean > the following: have one of the properties of the class such that it > uniquely > identifies the message being sent and then use the same property to update > the row in the database. > > Casting the UserState: > > myClass mailid = (myClass) e.UserState; > > Then ,mailid.myproperty will return me what I passed? > > I suppose I can try out the code. But, if I have completely misunderstood, > please enlighten me ... with some code snippets (?). Thanks. perfectly. That's exactly what you do. Jeff, thanks for the guidance/pointers. All works fine.
Show quoteHide quote "Jeff Johnson" wrote: > "AA2e72E" <AA2e***@discussions.microsoft.com> wrote in message > news:1CA5C82E-F25C-4783-AC2A-61D972856704@microsoft.com... > > >I am using System.Net.Mail to send mail asynchronously. I have an event > > handler that gets trigerred when the task is completed. > > > > One of the arguments of the event handler has a method UserState; > > UserState > > gets a unique GUID for the asynchronous task. > > > > How do I get this GUID when (or before) I send the mail? I'd like to > > record > > the GUID in a database table and then from the event handler, update the > > row > > with the outcome reported by the argument e. > > > > Thanks. > > > > SmtpClient client = new SmtpClient(mailClient); > > > > client.SendCompleted += new > > SendCompletedEventHandler(MailDeliveryComplete); > > > > public void MailDeliveryComplete(object sender, > > System.ComponentModel.AsyncCompletedEventArgs e) > > { > > LogMessage("Message token = " + e.UserState); > > > > > > } > > Assuming you're using the SendAsync() method, you pass this information in > the userToken parameter. If you need to pass more than one piece of > information, create a class and add your various items as properties, then > pass the class. In the event handler, you cast the UserState property back > into your class object. > > >
Other interesting topics
C# representation of VB.net "OrElse" operator?
How does managed code work? Future of CSharp vs future of VB MSN Display Picture in C# webservice MD5 hashes always unique? LINQ - retrieve differences between two generic Lists Compress and decompress with c#? Dataset_"Træk&Slip"_metoden_ Howto extend WPF UserControl |
|||||||||||||||||||||||