Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 666285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:48:07+00:00 2026-05-13T23:48:07+00:00

I have an application that uses MSWord automation to edit some documents, after they

  • 0

I have an application that uses MSWord automation to edit some documents, after they save and close word I need to grab the modified file and put it back on the repository, there is only one scenario where I can’t get it to work and that is
when the user makes changes to the file, selects to close word and selects yes to save the file

there are 2 events that I’m using:
DocumentBeforeSave
Quit

on the Quit event I’m trying to load the .docx file from disk but on this particular scenario I get an IOException because the file is still in use, somehow I need to wait until after the Quit event has been processed, which is when Word is actually closed and the file is no longer being used

right now I have it working using this

      word.Visible = true; 
        while (!wordDone) { //gets changed to true on the Quit event
            System.Threading.Thread.Sleep(100);
        }
        bool error = false;
        do {
            try { //need to load the contents of the modified file
                ls.Content = System.IO.File.ReadAllBytes(provider.GetFileName());
                error = false;
            }
            catch (System.IO.IOException) {
                error = true;
                System.Threading.Thread.Sleep(200);
            }
        } while (error);

while this works it is very ugly, I need a way to fire an event after the Quit event has been handled, or block the current thread while word is still running, or get an event after the document has been saved, the bottom line is I need a clean way to load the file after it has been saved and word is closed. DocumentAfterSave would be awesome, but doesn’t seem to exist.

I Also tried unhooking the Quit handler and calling word.Quit on the Quit handler, that made no difference

I’m also investigating the use of ManualResetEvent or related classes, so far it almost works, but I still need to pause after it has been signaled to make sure word is closed and the file is no longer in use

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:48:07+00:00Added an answer on May 13, 2026 at 11:48 pm

    I faced similar problem in the past as well. I dont think there is any nice clean way but instead of doing it like your above, how about considering this (will suit if you have a controlled environment)

    • Create word app
    • Get the Process ID immediately by using GetProcesses matching Winword and the last one in the list return should be the one you are after. This is not 100% reliable in multiuser environment.
    • After word quit, use the Thread.Sleep loop to ensure the PID no longer exist.
    • Reading the docx for your custom operations
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that uses a UITabBarController as its outer container. Each tab
I have an application that uses the Oracle MERGE INTO... DML statement to update
We have an application that uses Windows authentication to authenticate users with the database,
I have an application that uses the System.Diagnostics.Trace and System.Diagnostics.EventLog classes to generate the
I have a spring application that uses several services such as MySQL, PostgreSQL, and
I have a Spring application that uses JAX-WS to consume another web service. Everything
I have an iPhone application that uses a sqlite3 database for saving data and
I have a .Net application that uses their user settings. What is the best
We have an application that stores project information in a file by descending from
Nutshell: I launch a thread from my form, then some time later use the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.