Click here to Skip to main content
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 Los158.3K
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 OriginalGriff 277
1 Maciej Los 220
2 DamithSL 190
3 Raul Iloc 185
4 Richard MacCutchan 175
0 OriginalGriff 5,130
1 DamithSL 4,197
2 Maciej Los 3,670
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,821


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 30 Jun 2013
Copyright © CodeProject, 1999-2014
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