Introduction
Altough BackgroundWorker makes developing multi-threaded Desktop application quite easy, a developer should practically write their own code to fulfill the same task while developing an ASP.NET application.
This process includes dividing the data input into smaller parts,creating the threads, assigning jobs to threads, and collecting results from previously created threads.
To provide an easy and quick way of converting time-consuming operations, I have created a small library to enable using your own methods in a multi-threaded way. The whole idea is based on writing a method to perform a task and passing it to the library to run it multi-threaded instead of single-threaded.
Background
The project is mainly based on the combination of my two previous projects. One of them was to create a template engine such as DotLiquid to provide customizable reporting outputs. And the other one was basically speeding the wage calculation of 3600+ employees using a dynamic formulation based on Gold Parser.
I used the multi-threaded wage calculation engine and generalized it with the code from the template engine.
Using the code
Let's start with a code which is designed to run single-threaded.
private IList<Employee> m_employees
{
get
{
return Session["Employees"] as IList<Employee>;
}
set
{
Session["Employees"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
IList<Employee> eList = DAL.SelectHQL<Employee>("select p from Personel p", 5000);
m_employees = eList;
}
}
protected void btRunSingleThreaded_Click(object sender, EventArgs e)
{
try
{
object[] results = new object[m_employees.Count];
int counter = 0;
foreach (Employee emp in m_employees)
{
results[counter] = GetLastPosition(emp);
counter++;
}
}
Read more: Codeproject
0 comments:
Post a Comment