Click here to Skip to main content
15,884,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends ;
i want to show progress bar while i sent mail using this code


C#
MailMessage mail=new MailMessage(from,to,subject,body);
                    SmtpClient client=new SmtpClient(smtp);
                    client.Port = 587;
                    client.Credentials = new System.Net.NetworkCredential(from, pass);
                    client.EnableSsl = true;
                    client.Send(mail);
                    MessageBox.Show("Done","Succ",MessageBoxButton.OK);



please help
Thanks;
Posted
Updated 29-Jun-13 23:03pm
v2
Comments
Richard MacCutchan 30-Jun-13 4:11am    
Given how quickly those statements will execute it will probably not show on the screen.
Nitesh Kejriwal 30-Jun-13 4:51am    
You do not have any control on what stage the mail is while being sent . Hence, even if you put a progress bar, it wont show much impact. If you want to send multiple emails showing progress bar, it make sense.
Mike Meinz 30-Jun-13 7:38am    
There are no Callbacks from any of the above methods that you could use to update a progress bar. If you really wanted to do a progress bar, you would have to put a line of code in between each of the lines above to update the progress bar by some amount.

Example:

DisplayProgressBar();
MailMessage mail=new MailMessage(from,to,subject,body);
UpdateProgressBar(15);
SmtpClient client=new SmtpClient(smtp);
UpdateProgressBar(30);
client.Port = 587;
UpdateProgressBar(45);
client.Credentials = new System.Net.NetworkCredential(from, pass);
UpdateProgressBar(60);
client.EnableSsl = true;
UpdateProgressBar(75);
client.Send(mail);
UpdateProgressBar(100);

That said, the progress bar will advance so fast that it may not be worth it. How about just change the mouse pointer to an hourglass at the beginning and back to default at the end?

1 solution

or Just Send Mail Asynchronous using SendAsync method instead of Send method of SmtpClient

so that control returns immediately.

Display a ProgressBar,
with Style=Marquee,

Handle the SendCompleted event.

and Hide the ProgressBar control (or whatever) in this event, when mail sending is complete.

this will not show the progress of current mail, but at least better than just waiting for its completion.

-praveen.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900