.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

System.Threading AND email

Posted By:      Posted Date: August 24, 2010    Points: 0   Category :ASP.Net

Hi guys,

I really need some help (and also some code example), in how to use System.Threading to send emails.

The issue is:

a) I have a function that sends emails;

b) But I don't want to keep the customers waiting for the email being sent;

c) so, I figure it out that the System.Threading is the best way to do that; But I don't know how exactly I cant use it.

PLEASE, i'm VB - not C# - developer, and I really appreciate help in that language.

I can't use Windows Services or SQL Jobs...

Could you help me on this?



View Complete Post

More Related Resource Links

Email Help (System.Net.Mail)


Hi I have a annoying problem. 
I have created a page which takes users details for a quote.

I have then created the form to be emailed to both the user and myself. (Which works fine ATM)

However I would also like to be able to attach a file containing terms and conditions to the email.

I have tried doing this using 

EmailMsg.Attachments.Add(new Attachment("C:\\attachme.txt"));

But everytime that line of code is hit it fails and is caught by my try catch.

Take that line out and the email sends fine, put it in and it breaks the whole page.

Am I missing something really obvious?

smtp is noe sending email instantly,it makes a Queue in my local system

I am using a  smtp to send email from asp.net (C#)code.it sending some email instantly but many of email is making a queue in my Inetpub folder at local system.what could be the issue ? please help me to get rid from it.ThankxArvind

Email Encryption using System.Net.Mail assembly

Hi folks, Has anyone used the above assemblies to send emails using public key enryption, specifically PGP? Cheers Mark 

Sending email System.net.mail


Ok here's my problem. I have a contact page with a txtbox for users name, email and message for users to contact me.  When I send the message it goes through, but the senders email is always my email. Even though i have set it to the txtEmail.Text property. So when I reply, it sends me an email. What am I not seeing that I messed up. Also this is running from VS 2005.

                 protected void btnSubmit_Click1(object sender, ImageClickEventArgs e)

                 const string toAddress = "myemail@gmail.com";
                    MailAddress from = new MailAddress(txtEmail.Text, txtName.Text);
			        MailAddress to = new MailAddress(toAddress, "Admin");
			        MailMessage message = new MailMessage(from, to);

			        // set properties
			        message.Subject = txtName.Text + " has sent you an email!";
			        message.Body = txtMessage.Text;
                                message.IsBodyHtml = false;

			        //create smtp object
			        SmtpClient client = new SmtpClient();
                               client.EnableSsl = true;

                    catch(Exception ex)

Error while sending email using ASP.NET 2.0 -'System.Net.Mail.SmtpException: Failure sending mail


'System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed.   at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine)   at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)   at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)   at System.Net.Mail.SmtpReplyReader.ReadLine()   at System.Net.Mail.CheckCommand.Send(SmtpConnection conn, String& response)   at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from)   at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)   at System.Net.Mail.SmtpClient.Send(MailMessage message)   --- End of inner exception stack trace ---   at System.Net.Mail.SmtpClient.Send(MailMessage message) 

 i tried many things but still awaiting solution



sometimes  i get this error

 'System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: The remote name could not be resolved: 'smtp.mail.y

Embedding hyperlink in email using System.Net.Mail;


My goal is to embed a link in the email.

Purpose is that the user needs to click the link in his email to activate the account.

But my emailbody with the link is just shown as plain-Non clickabel text.

the body text looks like:

string mailBody = "please click the following link to activate your account:<br>

string mailBody = "please click the following link to activate your account:<br>" +
I use the follwing code
System.Net.Mail.AlternateView plainView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(System.Text.RegularExpressions.Regex.Replace(BodyText, @"<(.|\n)*?>", string.Empty), null, "text/plain");
System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(BodyText.Replace("\n","<BR>"), null  , System.Net.Mime.MediaTypeNames.Text.Html);


How do i embed this link in the receivers ema

How does System.Threading.Timer work (implementation details)


I've read a bunch of articles on the different .NET timers and still don't have a good understanding how the System.Threading.Timer class works.  My concern is whether I'm creating a bunch of timer threads in the thread pool.  I have this concern because one article said something about System.Threading.Timer using a thread pool thread to WAIT on the timer.  I'm hoping that each System.Threading.Timer class I create doesn't create a thread pool timer thread waiting on my timer interval.  I assume not.  Which is why I would like to know how it actually works.

For instance, let's say I create 50 System.Threading.Timer objects with a 5 second interval.  What happens?  Is there some interop call into unmanaged code which creates some timer resources and somehow signals some managed code when a timer has elapsed at which point the managed code queues a work item to the thread pool?  So in my example, at roughly the same point in time .NET would queue 50 work items to the thread pool?



Where is System.Threading.Parallel?


Where does one find the System.Threading.Parallel library? It is supposedly part of the BCL, according to ECMA 335, but Google only turned up three references to it, with one of them in the standard itself.

For those of you unfamiliar with this library, it is supposed to make parallel computing easier, by providing classes such as ParallelFor, ParallelWhile, and ParallelForEach.

System does not send an email to an approver when a custom workflow is cancelled


We have a custom workflow created using SharePoint Designer (SPD). The workflow starts when user submits a (InfoPath) form. The workflow sends an email to an approver. On one occasion, user submitted the form, workflow started, user (submitter) realized he had made a mistake and decided to cancel the workflow (using the procedure: Cancel a workflow in progress). In the meantime, the approver had already received an email and when the approver clicked on the link "Edit This Task" in his email, he got the following error message. We were hoping that SharePoint would have sent the approver a notification for the cancellation of the workflow. OOTB (Out-of-the-Box) workflow probably sends a cancellation notice to the approver. How can we achieve the same functionality in custom workflow?:

//////Error message when approver clicks on "Edit this Task" link in his email:

No item exists at http://ServerName/SiteAddress/Lists/My Workflow Tasks/DispForm.aspx?ID=2.  It may have been deleted or renamed by another user.

Web Parts Maintenance Page: If you have permission, you can use this page to temporarily clo

Applying transport rule on System.Net.Mailmessage C# email

I want to apply transport rule to block the recipients(DRM/IRM-Information Rights Management/Permission settings) from forwarding email received from a specific sender, is there a way to do this in MailMessage class itself instead of enabling this option at exchange server.

Email alert reverting to System Account, which has no email associated.


Hello, On my Virtual PC, MOSS 2007 I have these accounts:




System Account - SHAREPOINT\System

For some reason no matter which one of these I enter into the "Send Alerts To" in the New Alert form, it sets it to the last one I haev listed above, the System Account.

I've gone through the steps as I've done many times before to add a new alert to make sure I didn't miss anything, however, I am hitting the same problem when I try to set up a new alert on a list:

"The following users do not have e-mail addresses specified: BRUCEVPC\Administrator. Alerts have been created successfully but these users will not receive e-mail notifications until valid e-mail addresses have been provided"

"Set my e-mail address..."

Then, when I try to set my e-mail address, it takes me to the profile for the system account, but with no options to edit or add an email:

Home > My Sharepoint Sandbox > People and Groups > User Information > Edit Personal Settings

It only shows me:

Attach File 

Account SHAREPOINT\system      
Created at 1/2/2009 2:31 PM  by System Account  
Last modified at 1/2/2009 2

To list all running tasks - System.Threading.Tasks


Hi everyone,

I am working on System.Threading.Tasks namespace. My requirement is to see all the running tasks within a program, their state and interdependencies.

I have looked at the http://msdn.microsoft.com/en-us/library/system.threading.tasks.task.aspx but could not find a way that will list all running tasks. Would you please guide me how to approach and where to look for?



System.Threading.ThreadAbortException: Thread was being aborted


In my ASP.Net web application, one of the function is calling the WCF service that has been developed by .Net framework 3.0 using VS2005.It works fine on production and user can make request 8 times(calls) between client and service after that the web application got hanged and generated the following error message. But it works fine on development even more than 8 requests.

I given the proxy time out 20 min in the client side proxy setting.

Error message:

Hello World to C# Threading Part 1

In this post we will see how we can implement simple threading. Why do we need threading? When you want you application to do more then one thing at same time, then you need to implement threading. One usual and common scenario would be when your application needs to get data from some other resource like web services and you don't want you application GUI to be freeze during this time. In that sort of case you will run the code to access web services in separate thread so your application GUI won't freeze. The System.Threading namespace .NET provide interfaces to implement multi threading.

Threading in C#

What is Threading?
-Parallel execution of code pieces on CPU, commonly compiled codes started in a single thread but it is possible to create multi-threads within a program.


Multi-core processors are new standards on the user's hardware. By taking advantage of the multi-processing capabilities of these machines you can achieve significant performance upgrade with some minor changes in your code. When an application does not make use of threading techniques it is wasting valuable resources. This tutorial will cover the basic threading concepts and threading methods and properties.

Multi-threading in .NET: Introduction and suggestions

This article uses the C# type shorthands throughout - int for Int32 etc. I hope this makes it easier for C# developers to read, and won't impede any other developers too much. It also only talks about the C# ways of declaring variables to be volatile and locking monitors. Developers using other languages can find the equivalents in their own preferred environment, I'm sure.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend