#region Start Mail Delevery
///
/// Start Mail Delevery
private void btnStart_Click(object sender, EventArgs e)
{
StartMailThreading();
}
#endregion
#region Start Mail Threading
///
/// Start Mail Threading
///
public void StartMailThreading()
{
// Create the worker thread and start it
ThreadStart starter = new ThreadStart(this.UpdateListBox);
Thread t = new Thread(starter);
t.Start();
// Loop 4 times, adding a message to the ListBox each time
for (int i = 0; i < 4; i++) ;
{
this.listBoxSendItems.Items.Add("Campaign Started");
this.listBoxSendItems.Update();
// Process any queued events on the UI thread
Application.DoEvents();
// Suspend processing for 1 second
Thread.Sleep(1000);
}
this.listBoxSendItems.Items.Add("Last message from UI thread");
this.listBoxSendItems.Update();
}
#endregion
#region Update ListBox Control
///
/// Update ListBox Control
///
public void UpdateListBox()
{
for (int j = 0; j < 20; j++)
{
// Set the message to be added to the ListBox from the worker
// thread
this.Message = "Worker thread loop count = " + j.ToString();
// Invoke the WorkerUpdate method in the ListBox’s thread
// context
this.listBoxSendItems.Invoke(new EventHandler(WorkerUpdate));
Thread.Sleep(100);
}
}
#endregion
#region WorkerUpdate
// The delegate that’s called from the worker thread
// to update the ListBox
public void WorkerUpdate(object sender, EventArgs e)
{
this.listBoxSendItems.Items.Add(this.Message);
this.listBoxSendItems.Update();
}
#endregion
Articles
- Articles(C#.NET) (3)
- ASP.NET (6)
- Asp.Net(Email) (1)
- Asp.net(Image) (2)
- Asp.Net(Web.Config) (2)
- C#.NET (5)
- C#.NET Threading (3)
- C#.NET(ASP.NET) (4)
- Comments in PHP (1)
- Encryption In PHP (1)
- iPhone (Articles) (1)
- JavaScript (1)
- Json with PHP (1)
- LINQ (1)
- PHP (2)
- PHP Constant (1)
- PHP Operators (1)
- PHP Print Command (1)
- PHP Tutorial (2)
- Strings In PHP (1)
- Variable Declaration In PHP (1)
- WPF (1)
- XAML (2)
About Me
Help Link
Followers
Posted by
Sreejith A.K
Monday, April 5, 2010
comments (0)
Labels:
C#.NET Threading
Subscribe to:
Posts (Atom)