Multiple Word Documents Concurrent Updating in C#
Created
June 16, 2025 07:04
-
-
Save openize-com-gists/d69f7e1a8087648e9fd88f542a90d686 to your computer and use it in GitHub Desktop.
Multiple Word Documents Concurrent Updating in C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| namespace OpenizeConcurrentDocumentExample | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| // Concurrently updating three documents using Openize.Words | |
| // Supported in v23.12.0 | |
| var task1 = System.Threading.Tasks.Task.Run(() | |
| => ManipulateDocument("doc1.docx", "doc1_Threaded.docx")); | |
| var task2 = System.Threading.Tasks.Task.Run(() | |
| => ManipulateDocument("doc2.docx", "doc2_Threaded.docx")); | |
| var task3 = System.Threading.Tasks.Task.Run(() | |
| => ManipulateDocument("doc3.docx", "doc3_Threaded.docx")); | |
| // Wait for all tasks to complete | |
| System.Threading.Tasks.Task.WaitAll(task1, task2, task3); | |
| Console.WriteLine("All tasks completed."); | |
| } | |
| static void ManipulateDocument(string inputFileName, string outputFileName) | |
| { | |
| var doc = new Openize.Words.Document(inputFileName); | |
| var paragraph = new Openize.Words.IElements.Paragraph(); | |
| paragraph.AddRun(new Openize.Words.IElements.Run | |
| { | |
| Text = $"This is the paragraph appended to {inputFileName}" | |
| }); | |
| var body = new Openize.Words.Body(doc); | |
| body.AppendChild(paragraph); | |
| doc.Save(outputFileName); | |
| Console.WriteLine($"Task completed for {inputFileName}"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment