Nevron Gauge for SharePoint
Skip Navigation Links
C# Corner Home
Forum Home
Latest 50
Unanswered
Win Prizes
All Time Leaders
Jump to CategoryExpand Jump to Category
Login 
    Welcome Guest!
 Search Forum For :  
X
 Login
Please login to submit a new post, reply and edit exiting posts, see user profiles, and access more features. If you are not a registered member, Register here.
User Id / Email:
Password:  
Forgot Password | Forgot UserName
   Home » C# Language » Starting Tasks after Tasks Finish
       
Author Reply
A Repasky
posted 81 posts
since May 25, 2011 
from

Starting Tasks after Tasks Finish

  Posted on: 02 Feb 2012       
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
       
Nevron Gauge for SharePoint
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Team Foundation Server Hosting
 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Advertise with us
Current Version: 5.2011.3.12
 © 1999 - 2012  Mindcracker LLC. All Rights Reserved