Software Programs and Projects

This Software Programs and Projects include programing tips and technology using different languages like VC++,ASP,JSP C#.Net,PHP,VB.Net,JavaScript,ASP.NET .Software Programs and Projects blog mainly support to software programmers and provide help through the mail.

#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

private void FormCampaignLog_Load(object sender, EventArgs e)
{
Thread trd = new Thread(new ThreadStart(this.startProgress));
trd.IsBackground = true;
trd.Start();
}

void startProgress()
{
for (int i = 0;i<100;i++)
{
SetControlPropertyValue(progressBar1, "value", i); //This is a thread safe method
System.Threading.Thread.Sleep(100);
}
}

private void SetControlPropertyValue(Control oControl, string propName, object propValue)
{
if (oControl.InvokeRequired)
{
SetControlValueCallback d = new SetControlValueCallback(SetControlPropertyValue);
oControl.Invoke(d, new object[] { oControl, propName, propValue });

}
else
{
Type t = oControl.GetType();
PropertyInfo[] props = t.GetProperties();
foreach (PropertyInfo p in props)
{
if (p.Name.ToUpper() == propName.ToUpper())
{
p.SetValue(oControl, propValue, null);

}
}
}
}