TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
A Repasky
NA
231
183.9k
Starting Tasks after Tasks Finish
Feb 2 2012 8:48 PM
I attached the entire code, but the code I am interested in is creating tasks to combine images using the program ImageMagick. I read in tif file names that are named using the 12 char invoice number. I want to combine 2 together with 2 instruction pages. Since each invoice is independent of the other, each can run in parallel. So I read in one invoice (2 files) and combine into another tif file. There are 10's of thousands. Takes a long time to run. So I have 4 tasks. Each can handle one invoice at a time. When each task in done, it can start another invoice. I just do not know the formats of the Task class to use. I have tried a lot of things. I know that I have to have an inner loop added, but I just do not know how to do that with the Task class. This is the code that I am talking about, but the whole program is attached.
DirectoryInfo
directoryInfo =
new
DirectoryInfo
(
@"C:\Examples\TaskImageMagick\Tiff\"
);
List
<
FileInfo
> list = directoryInfo.GetFiles().ToList();
StringBuilder
args =
new
StringBuilder
();
string
previousFileKey =
""
;
//Remove files from list, only need numbered files,then sort
list.RemoveAll(n => n.Name ==
"Instructions.tif"
);
list.Sort((a, b) =>
string
.Compare(a.Name, b.Name));
//Initialize tasks
Task
t1 =
new
Task
(() => CombineTiff(args.ToString(), previousFileKey));
Task
t2 =
new
Task
(() => CombineTiff(args.ToString(), previousFileKey));
Task
t3 =
new
Task
(() => CombineTiff(args.ToString(), previousFileKey));
Task
t4 =
new
Task
(() => CombineTiff(args.ToString(), previousFileKey));
foreach
(
var
item
in
list)
{
if
(previousFileKey == item.Name.Substring(0, 12))
{
// add to arg list
args.Append(
" +page "
);
args.Append(item.Name);
args.Append(
" +page "
);
args.Append(
"Instructions.tif"
);
previousFileKey = item.Name.Substring(0, 12);
}
else
{
//Run combine tiff process
if
(t1.IsCompleted)
t1.Start();
else
if
(t2.IsCompleted)
t2.Start();
else
if
(t3.IsCompleted)
t3.Start();
else
if
(t4.IsCompleted)
t4.Start();
//clear args
args =
new
StringBuilder
();
// add to arg list
args.Append(
" +page "
);
args.Append(item.Name);
args.Append(
" +page "
);
args.Append(
"Instructions.tif"
);
previousFileKey = item.Name.Substring(0, 12);
}
}
I tried to write this out, so I hope it is understandable.
I hope someone can help and I would really appreciate it.
Thanks for the help.
Arep
Attachment:
tasks.zip
Reply
Answers (
0
)
Out and Ref in C#
CRYSTAL REPORT IS NOT DISPLAY RESULT