M
mac
hi,
I have created a windows service in C# that reads data from word document
and fills in sql table. This service runs every two minutes. The issue is
that it creates new instance of winword.exe everytime it runs. If i see task
manager there is multiple instance of winword.exe. That way my system crashes
after creating 9-10 process. How can i avoid that. Here is the code
word.ApplicationClass a = new
Microsoft.Office.Interop.Word.ApplicationClass();
word.Document d = a.Documents.Open(ref templateLocation, ref missing, ref
missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing);
/* process data
*/
if (d != null)
{
d.Close(ref saveChanges, ref missing, ref missing);
d = null;
}
if (a != null)
{
a.Quit(ref missing, ref missing, ref missing);
a = null;
}
GC.Collect();
I also tried to read the existing process by using
a = Marshal.GetActiveObject("Word.Application") as word.ApplicationClass;
but it throws an exception when i try to process the document for this
application class..
I also tried to create the word application in the constructor of service.
But when i try to open the document using
d = a.Documents.Open(ref templateLocation, ref missing, ref missing, ref
missing, ref missing, ref missing,ref missing, ref missing, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref
missing);
It just exists the service even though i have it in try catch block with
comexception.
I have created a windows service in C# that reads data from word document
and fills in sql table. This service runs every two minutes. The issue is
that it creates new instance of winword.exe everytime it runs. If i see task
manager there is multiple instance of winword.exe. That way my system crashes
after creating 9-10 process. How can i avoid that. Here is the code
word.ApplicationClass a = new
Microsoft.Office.Interop.Word.ApplicationClass();
word.Document d = a.Documents.Open(ref templateLocation, ref missing, ref
missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing);
/* process data
*/
if (d != null)
{
d.Close(ref saveChanges, ref missing, ref missing);
d = null;
}
if (a != null)
{
a.Quit(ref missing, ref missing, ref missing);
a = null;
}
GC.Collect();
I also tried to read the existing process by using
a = Marshal.GetActiveObject("Word.Application") as word.ApplicationClass;
but it throws an exception when i try to process the document for this
application class..
I also tried to create the word application in the constructor of service.
But when i try to open the document using
d = a.Documents.Open(ref templateLocation, ref missing, ref missing, ref
missing, ref missing, ref missing,ref missing, ref missing, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref
missing);
It just exists the service even though i have it in try catch block with
comexception.