Note that there are some explanatory texts on larger screens.

plurals
  1. POTimer usage in Thread Pool
    primarykey
    data
    text
    <p>I am developing a windows application for my company that runs on the server. It is a multi threaded application, and i am using Thread Pool for that.</p> <p>My Application Email module consists of 3 major methods. 1st method gets new campaigns from database, second method decides to whom the campaign is going to be sent via email and third method sends it.</p> <p>When I start the application, 1st method goes into Thread Pool, if there is a new campaign, 2nd method is invoked with the campaign info. But while these all are happening, first method has to check database in every three seconds if there is a new campaign or not.</p> <p>I am not sure if I have to use System.Windows.Forms.Timer class for that or System.Threading.Timer??</p> <p>And I am not sure how to implement it? Am I going to use Invoke Function to invoke thread outside the main UI? Could you please post an example code and suggest best practices?? Thanks a lot</p> <p>Here is my code :</p> <pre><code>private void btnStart_MouseClick(object sender, MouseEventArgs e) { smartThreadPool = new SmartThreadPool(); workItemGroup = smartThreadPool.CreateWorkItemsGroup(1); workItemGroup.QueueWorkItem(CheckNewCampaigns); //smartThreadPool.QueueWorkItem(new WorkItemCallback(this.CheckNewCampaigns)); } private object CheckNewCampaigns(object state) // 1st method { StringBuilder builder = new StringBuilder(); IEnumerable&lt;Campaigns&gt; CampaignsList = DatabaseManager.GetCampaignsList(DatabaseManager.GetNewCampaigns()); foreach (Campaigns Campaign in CampaignsList) { builder.AppendFormat("New Campaign Arrived($) --&gt; {0}\r\n", DateTime.Now.ToLongTimeString()); builder.AppendFormat("CampaignID --&gt; {0}\r\n", Campaign.CampaignID); builder.AppendFormat("CustomerID --&gt; {0}\r\n", Campaign.CustomerID); builder.AppendFormat("ClientID --&gt; {0}\r\n", Campaign.ClientID); builder.AppendFormat("Title --&gt; {0}\r\n", Campaign.Title); builder.AppendFormat("Subject --&gt; {0}\r\n", Campaign.Subject); builder.AppendFormat("Status --&gt; {0}\r\n", Campaign.Status); } Console.WriteLine(builder.ToString()); workItemGroup.QueueWorkItem(new WorkItemCallback(this.PrepareCampaignEmail), 2); return true; } private object PrepareCampaignEmail(object CampaignID) // Second Method { int campaignID = (int)CampaignID; IEnumerable&lt;Campaigns&gt; CampaignDetailsList = DatabaseManager.GetCampaignsList(DatabaseManager.GetCampaignDetails(campaignID)); // bir tane campaign gelmekte IEnumerable&lt;Subscribers&gt; SubscribersList = DatabaseManager.GetCampaignSubscribersList(DatabaseManager.GetCampaignSubscribers(campaignID)); ArrayList test = new ArrayList(); DataTable dtCustomValuesForCampaign = DatabaseManager.GetCustomValuesForCampaign(campaignID); foreach (Subscribers subscriber in SubscribersList) { workItemGroup.QueueWorkItem(new WorkItemCallback(this.SendEmail), subscriber.Email); } return true; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload