c# - Design Model and Hints For Multithreaded Win Form Application -


i trying design multithreaded windows application serves our clients send emails fastly customers(there can millions there big telecommunication company), , need design hints.(i sorry q long)

i read articles multithreaded applications. read smartthread pool, .net threadpool, task parallel library , other questions. not come correct design. logic :

within start of program(email engine), timer starts , check if there email campaigns in database(campaigns table) has status 1(new campaign).

if there are, campaign subscribers should queried db , should written table(sqlbulkcopy) called subscriberreports table , update campaign's status 2 in campaigns table.

timer listens campaigns status 2 call method customize campaign each subscriber, creates struct has customized properties of subscriber.

thirdly sendemail method invoked send email via smtp. tried far below(i know threadpool wrong here, , have bunch of other mistakes). can pls suggest , me how design such application. highly appreciate help. alot time.

private void processtimer(object source, elapsedeventargs e) {     campaigns campaign = new campaigns();     ienumerable<campaigns> campaignsliststatusone = // campaign properties list     ienumerable<campaigns> campaignsliststatustwo = // campaign properties list                  foreach (campaigns _campaign in campaignsliststatusone)     {         threadpool.queueuserworkitem(new waitcallback(checknewcampaign), _campaign.campaignid);     }      foreach (campaigns _campaign in campaignsliststatustwo)     {         threadpool.queueuserworkitem(new waitcallback(customizemail), _campaign.campaignid);     } }  private void checknewcampaign(object state) {     int campaignid = (int)state;     datatable dtcampaignsubscribers = // subscribers based on campaign id     campaign.updatestatus(campaignid, 2); }  private void customizemail(object state) {     int campaignid = (int)state;     campaigncustomazition campaigncustomizer;     ienumerable<subscriberreports> reportlist = // subscribers sent reports table      foreach (subscriberreports report in reportlist)     {   // 3 database related methods here         campaigncustomizer = new campaigncustomazition(report.campaignid, report.subscriberid);          campaigncustomizer.customizesource(report.campaignid, report.subscriberid, out campaigncustomizer.source, out campaigncustomizer.format);         campaigncustomizer.customizecampaigndetails(report.campaignid, report.subscriberid, out campaigncustomizer.subject, out campaigncustomizer.fromname, out campaigncustomizer.fromemail, out campaigncustomizer.replyemail);         campaigncustomizer.customizesubscriberdetails(report.subscriberid, out campaigncustomizer.email, out campaigncustomizer.fullname);          threadpool.queueuserworkitem(new waitcallback(sendmail), campaigncustomizer);     } }   private void sendmail(object state) {     campaigncustomazition campaigncustomizer = new campaigncustomazition();     campaigncustomizer = (campaigncustomazition)state;     //send email based on info @ campaigncustomizer via smtp , update db record if success.  } 

there little gained here using threading. threads buy more cpu cycles. assuming have machine multiple cores, pretty standard these days. that's not need job done quicker. need more dbase , email servers. surely have 1 of each. program burn very little core, waiting dbase query , email server complete job.

the way ahead overlap delays of each. 1 thread waiting dbase engine, other waiting email server. better 1 thread waiting both.

that's not buy either though, there's big mismatch between two. dbase engine can give thousands of email addresses in second, email server can few hundred emails in second. throttled how fast email server works.

given low odds of getting ahead, i'd recommend don't try trouble threading @ all. has knack producing hard diagnose failure if don't lock properly. amount of time can spend on troubleshooting can exceed operational gains moving wee bit faster.

if contemplating threading avoid freezing user interface that's reasonable use threading. use backgroundworker. msdn library has excellent it.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -