Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can you let me know whether following tasks is achievable or not, if yes then how, if no then why.

I have got mailing function written in C#, i need to send 50 mails at one shot. Now i can achieve this by two ways either run 50 exes at one time or by implementing threading concept in single program.

But as expected threading concept is not giving me result or can say performance as i am getting by running multiple exes. Can you help me by giving suggestion or concept for running one program and get the performance of running multiple exes.
Posted
Comments
[no name] 1-Jan-15 7:21am    
And if you need to send 1000 mails you think about to start 1000 exe?
What you mean with "threading concept"? Instead of 50 exe 50 threads?

There is a thing which also is called loop. Either "for" or also "while"...and yes not a bad idea to loop over the 50 (maybe 1000) mails in a seperated thread to send them.
BillWoodruff 1-Jan-15 8:39am    
Sending 50 e-mails should be doable in some kind of loop ... unless each e-mail contains megabytes of content and/or attachments.

Are you absolutely sure you need to send them all "at once" ?

Use parallel programming[^]. This means that you make use of the different cores in your computer, if you have multiple. You can distribute your work across the different cores, which gives better performance.
 
Share this answer
 
Comments
George Jonsson 1-Jan-15 8:35am    
Should solve the problem.
Dave Kreskowiak 1-Jan-15 14:25pm    
We are assuming what the problem is. The OP doesn't really define the parameters of the problem so we don't really know. Everyone is assuming what the problem appears to be.
George Jonsson 2-Jan-15 0:54am    
Good point.
First of all, 50 e-mails is next to nothing to care about performance that much. Threading does not improve your throughput much, as the bottleneck would be the network. Moreover, when you create number of threads which is much more than the number of your cores, you can make your throughput worse, due to overhead of threads. You need to understand the primary purpose of threads is not performance.

You are missing the most apparent and practical solution: to send 50 messages, you don't need 50 processes. You can run only one process which sends 50 messages sequentially.

Happy New Year!

—SA
 
Share this answer
 
v2
Comments
[no name] 1-Jan-15 13:06pm    
+5Bruno
Sergey Alexandrovich Kryukov 1-Jan-15 13:43pm    
Thank you, Bruno.
Happy New Year!
—SA
As already have been mentioned that this is not your application's problem or the source code's problem. The problem in real is the network connection through which you're going to send the emails. And email is a cycle, which is executed as,

Connect to SMTP Server
|-> Transfer Credentials
    |-> Send data, recipient, subject and other fields
    |-> Get response
    |-> Transfer response back
    |-> If more emails to be sent, repeat this


.. so the major factor to this is the connection that you're using. Sergey is right, threading won't help infact it will create a new problem on your own system, more executions on the machine. Threading might be applied where you are to go into an async programming or so, but just to send 50 emails, starting 50 processes is insane idea. Yes, it will be a good idea to create an async method that would send these emails asynchronously each time and in 50 loops etc. For more on Async programming, please read this MSDN documentation[^] and all other resources attached in it.

A simple loop, meant to send the 5 emails through my 8MB internet connection using Gmail server would take more like 10 seconds. If I had to improve this, I would try to increase the bandwidth to allow more data to be sent and recieved and I would also try to get any premium subscription from the server (if they allow any) to improve the response rate from their side.
 
Share this answer
 
v2
Comments
yusuf_ahmed 2-Jan-15 2:57am    
Thanks to all of you for your valuable suggestion, will go through each and will surely let you know the conclusion.

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