Mr Dog
Mr Dog

Reputation: 396

Multi-Threading/Task making minimal difference, how to speed up process

I feel like I am doing something wrong here and not sure what, because I am not noticing a big difference with respect to multi-threading.

I have a 'Convert_Data' function that does a fair amount of processing of data. I tested it using 1 Task and saw that it was able to finish in 8 Seconds. When attempting to split the work into 4 task the overall reduction was just 2 seconds. I was expecting for it to atleast cut processing in half?

t1 = Task.Factory.StartNew(Sub() Convert_Data(Filter, 0, CInt(GridView1.RowCount / 4)))
t2 = Task.Factory.StartNew(Sub() Convert_Data(Filter, CInt(GridView1.RowCount / 4) + 1, CInt(GridView1.RowCount / 2)))
t3 = Task.Factory.StartNew(Sub() Convert_Data(Filter, CInt(GridView1.RowCount / 2) + 1, CInt(GridView1.RowCount / 3)))
t4 = Task.Factory.StartNew(Sub() Convert_Data(Filter, CInt(GridView1.RowCount / 3) + 1, GridView1.RowCount))

I break up the task based on the number of rows in my gridview. So each task gets a quarter of the files to process. I am very new to tasks and not sure if I am doing something wrong. Any comments/suggestions?

I noticed task 4 takes a fair amout longer to complete as opposed to the others.

The Conver_Data sub (Filter, StarRow, End Row) So if there are 100 files;

Task 1 will go from 0 - 25

Task 2 will go from 26 - 50

Task 3 will go from 51 - 75 &

Task 4 will go from 76 - 100

Upvotes: 1

Views: 106

Answers (1)

Brian Hooper
Brian Hooper

Reputation: 22044

Shouldn't the code read something like...

t1 = Task.Factory.StartNew(Sub() Convert_Data(Filter, 0, CInt    (GridView1.RowCount / 4)))
t2 = Task.Factory.StartNew(Sub() Convert_Data(Filter, CInt(GridView1.RowCount / 4) + 1, CInt(GridView1.RowCount / 2)))
t3 = Task.Factory.StartNew(Sub() Convert_Data(Filter, CInt(GridView1.RowCount / 2) + 1, CInt(3 * GridView1.RowCount / 4)))
t4 = Task.Factory.StartNew(Sub() Convert_Data(Filter, CInt(3 * GridView1.RowCount / 4) + 1, GridView1.RowCount))

As things stand, your first task appears to do 1/4 of the work, the second another quarter, the third 1/6th of it, and the last 2/3rds of the job.

Upvotes: 2

Related Questions