I went through this once. Try closing the workbook first:
book.Close(). In my experience, there is no need to call ReleaseComObject on
every Excel object, but you can play with that and see what works for you.
"ChrisBowringGG@gmail.com" wrote:
[color=blue]
> Christof,
>
> could you explain why the following code doesn't kill the Excel
> process:
>
> Application application = new ApplicationClass();
>
> try {
> Workbooks books = application.Workbooks;
> Workbook book = books.Open(BookPath, false, true,
> Type.Missing, Type.Missing, Type.Missing, Type.Missing,
> Type.Missing, Type.Missing, Type.Missing, Type.Missing,
> Type.Missing, Type.Missing, Type.Missing, Type.Missing);
>
> application.DisplayAlerts = false;
>
> XmlMaps maps = book.XmlMaps;
> XmlMap dataMap = maps["Data_Map"];
> dataMap.ImportXml(document.OuterXml, (object)true);
> application.Calculate();
> XmlMap outputMap = maps["Output_Map"];
> outputMap.Export(outputPath, true);
>
> Marshal.ReleaseComObject(outputMap);
> outputMap = null;
>
> Marshal.ReleaseComObject(dataMap);
> dataMap = null;
>
> Marshal.ReleaseComObject(maps);
> maps = null;
>
> Marshal.ReleaseComObject(book);
> book = null;
>
> Marshal.ReleaseComObject(books);
> books = null;
> }
> finally {
> application.Quit();
> Marshal.ReleaseComObject(application);
> application = null;
> GC.Collect();
> GC.WaitForPendingFinalizers();
> }
>
> I can't see any objects I've referenced that I haven't released.
>
> Thanks,
>
> Chris.
>
> Christof Nordiek wrote:[color=green]
> > See Inline
> > <ChrisBowringGG@gmail.com> schrieb im Newsbeitrag
> > news:1127211606.853485.178180@g49g2000cwa.googlegr oups.com...[color=darkred]
> > > When you use Application.Quit() on an Excel application,
> > > there can still be an instance of Excel running,
> > > as seen in Task Manager.
> > >
> > > You can try following the advice on MSDN:
> > >
> > >
http://support.microsoft.com/kb/Q317109
> > >
> > > but this didn't solve the problem for me.[/color]
> >
> > It works, but you have to call ReleaseComObject on every!!! excel object
> > your referencing.
> > Even on collection.
> > So instead of
> > Excel.Workbook workbook = oApp.Workbooks[0]:
> >
> > you've got to use
> > Excel.Workbooks workbooks = oApp.Workbooks;
> > Excel Workbook workbook = workbooks[0];
> >
> > And then call ReleaseCommObject on workbooks as well.
> >[color=darkred]
> > >
> > > Instead, I used a crow-bar and did the following:
> > >
> > > foreach (Process process in Process.GetProcessesByName("Excel")) {
> > > process.Kill();
> > > }
> > >[/color]
> > That's Dangerous.
> > You can't be sure the user is not running another Excel-session.
> >
> > Christof[/color]
>
>[/color]