.NET 4.0 makes Parallel programming easy. Below is an example of how to replace text across many .docx documents in parallel.
This example contains 4 functions.
1) Replace: This function opens a document and does the text replace.
2) NonParallel_ReplaceText: This is how you would replace text across multiple documents without using parallel execution. This is included for comparisons sake.
3) Parallel_ReplaceText: This is how you would replace text across multiple documents in parallel.
4) Main: This function does the work sequentially and then in parallel and prints the time taken for both.
Before running this code replace the line
DirectoryInfo di = new DirectoryInfo(@"C:\Users\Cathal\Desktop\multiple");
with a directory on your machine that contains many .docx documents.
1) There is over head when executing code in Parallel. Make sure your doing enough work to justify Parallel execution. For example: if you run this code on 4 small documents, the function NonParallel_ReplaceText may run faster than its parallel equivalent.
2) Run this example without the debugger, the debugger adds overhead which makes this code run significantly slower.
3) You can download and build the latest version of DocX.dll from here http://docx.codeplex.com/SourceControl/list/changesets#.