I am trying to send a message after saving the document, but since the message box is activated immediately, filling document is giving an error. After completing the Word document filling process, how can we give a message?
oWord.ActiveDocument.SaveAs2(@"C:\Users\Fatih\Desktop\\Sözlesme Metni.docx");
MessageBox.Show("Belge 'Sozlesmemetni' adiyla masaüstüne kaydedildi.");
System.Runtime.InteropServices.Marshal.ReleaseComObject(oWordDoc);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord);
oWordDoc = null;
oWord = null;

Mohamed Azarudeen ZRank #297 · 8.5K reputationPosted Jul 8, 2023, 12:01 PM EDT
Hi
, you can use the MessageBox asynchronously using
async/awaitusing Word = Microsoft.Office.Interop.Word; // ... async Task SaveAndShowMessageAsync() { var oWord = new Word.Application(); var oWordDoc = oWord.Documents.Add(); // Fill the document here // Save the document asynchronously await Task.Run(() => { oWord.ActiveDocument.SaveAs2(@"C:\Users\Fatih\Desktop\\Sözlesme Metni.docx"); }); // Release COM objects System.Runtime.InteropServices.Marshal.ReleaseComObject(oWordDoc); System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord); oWordDoc = null; oWord = null; // Show the message box after saving is completed MessageBox.Show("Belge 'Sozlesmemetni' adiyla masaüstüne kaydedildi."); }Mehmet FatihRank #1,474 · 1.1K reputationPosted Jul 8, 2023, 12:35 PM EDT
Thanks Mohamed. If I applied it right, it gives these mistakes.