Click here to Skip to main content
11,409,801 members (37,969 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WPF
Hello Friends ;
i want to show progress bar while i sent mail using this code


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 29-Jun-13 23:09pm
Edited 30-Jun-13 0:03am
Maciej Los177.4K
v2
Comments
Richard MacCutchan at 30-Jun-13 4:11am
   
Given how quickly those statements will execute it will probably not show on the screen.
Nitesh Luharuka at 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 at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 300
1 OriginalGriff 285
2 Dave Kreskowiak 115
3 Andy Lanng 115
4 Maciej Los 100
0 Sergey Alexandrovich Kryukov 8,731
1 OriginalGriff 6,895
2 Maciej Los 3,332
3 Abhinav S 3,248
4 Peter Leow 3,059


Advertise | Privacy | Mobile
Web01 | 2.8.150414.5 | Last Updated 30 Jun 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100