?? ?? ???? Microsoft Office ????????? ?? Microsoft Visual Basic .NET ?? Microsoft Visual C# .NET ???????? ??, ?? Office ????????? ???? ??? ???? ???? ???
???? ???????????? ???
?? ???????? ??? ?? ??? ???? COM ???????? Visual Studio .NET, ???????? ??? ?? ?? ?????? Callable ???? (RCW) ??? ???? ??? RCW marshals .NET ????????? ?? COM ???????? ?? ??? ??? ??? RCW ?????? ?????? COM ???????? ?? ???? ??? ?????, ??? ??? ?????? RCW ?? ???? ???? ???? ??? ??, COM ???????? ???? ??? ?????
????????? ???? ?? Office ????????? ???? ??, ????????? ???? ?? ???? ??????? ??? ????? ?????? ?? ??? ????:
- ?? ???????? ???? ?? ?? ?? ??? ??? ????? ????? ?????? ?? ???, ??? ?? ????? ?????? ?? ?????
oBook = oExcel.Workbooks.Add()
?????:
dim oBooks as Excel.Workbooks
oBooks = oExcel.Workbooks
oBook = oBooks.Add()
- ?????System.Runtime.InteropServices.Marshal.ReleaseComObject?? ?? ?????? ?? ??? ???????? ?? ????? ?? ??? ??? ?? decrements RCW ?? ???? ?? ?????? ???
- ????? ?? ??? ?? ?? ??????, ??? ?? ????? ???? ?? ?????? ???? ????,??.
- ????????? ???????? ???? ???? ?? ??? ????? ?? ????? ???? ?? ??? Office ????????? ???????? ?? ?????? ???
?? ??????? ??????? ?????? ??..
??????? ?? ???: ??????? ???? ?? ??? ???
- Visual Studio .NET ?? ??????? ?????
- ????? ???????????? ??,????? ????-????? ????, ?? ???? ????????????. ?? ???????Visual Basic ???????????? ????Windows ??????????? ????? ????OK. Form1 ???????? ??? ?? ???? ??..
- ???? ?????? ??????Microsoft Excel ???????? ?????????. ??? ???? ?? ???, ????? ????? ?? ???? ????::
- ????? ????????????????? ??,?????? ??????.
- ????? ????COM??? ???, Excel ?? ??? ???????? ????????? ?? ?????? ?????, ?? ???? ??? ????? ??????? ????.
Microsoft Excel 2002: ?? ???Microsoft Excel 10.0 ???????? ?????????
???:??? ???? ??? ??? ?? ????, ?? ???????? ?? ?? ?? ??????? ???? ?? Microsoft Office XP ???????? Interop Assemblies (PIAs) ?? ??????? ?????Office XP PIAs ?? ???? ??? ???????? ??????? ?? ??? Microsoft ???????? ??? ???? ????? ?? ??? ????? ???? ?????? ?? ????? ????:328912
(http://support.microsoft.com/kb/328912/
)
Microsoft Office XP ???????? ?????? assemblies (PIAs) ??????? ???? ?? ??? ?????? ???
Microsoft Office Excel 2003: ?? ???Microsoft Excel 11.0 ???????? ????????? - ????? ????,OK??????????? ??????????? ????? ???? ??? ?? ??????? ???? ?? ??? ???
- ????? ????????????? ??,????? ?????, ?? ??? ????? ?????Form1 ?? ????????? ?????
- ???-????? ????Button1. ?????? ?? ??? ??? ????? ????? ????..
- ????? ??? Form1.vb ?? ???? ??? ??? ??????:
Imports Microsoft.Office.Interop
- ??? ????? ??? ????? ??? ?? ???????????? ????
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
End Sub
?????: ?? ???
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oApp As New Excel.Application()
Dim oBook As Excel.Workbook = oApp.Workbooks.Add
Dim oSheet As Excel.Worksheet = oApp.ActiveSheet
oSheet = Nothing
oBook.Close(False)
oBook = Nothing
oApp.Quit()
oApp = Nothing
Debug.WriteLine("Sleeping...")
System.Threading.Thread.Sleep(5000)
Debug.WriteLine("End Excel")
End Sub
- ????????? ?? ????? ?? ??? F5 ??????
- Windows ????? ??????? ?????? Visual Studio ??? ???? ????? ????? ?? ??? ?????? ????? ????????? ????? ???? ??? ????? ???? ?? ??? ???? ?? Excel.exe ?? ??????? ??? ????? ????????????????? ????
- Excel ?? ?????? ??? ?? ???? ????? ???? ??? ?? ?? ?? sleeping ????????? ?? ???? ??? ????? ????? ??? ???? ?? ??? ???? ?? Excel ?? ??? ????? ???? ????????????????? ????
- ?? ?? ??? "??????" ??? ??? ??????????? ?? ??, ?? Office ????????? ???? ?? ????? ?? releases ?? ???? ??? 5 ??? ?????? ????? ??? ?? ???????????? ????:
Private Sub NAR(ByVal o As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
Catch
Finally
o = Nothing
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oApp As New Excel.Application()
Dim oBooks As Excel.Workbooks = oApp.Workbooks
Dim oBook As Excel.Workbook = oBooks.Add
Dim oSheet As Excel.Worksheet = oApp.ActiveSheet
NAR(oSheet)
oBook.Close(False)
NAR(oBook)
NAR(oBooks)
oApp.Quit()
NAR(oApp)
Debug.WriteLine("Sleeping...")
System.Threading.Thread.Sleep(5000)
Debug.WriteLine("End Excel")
End Sub
If you are using Visual C# .NET, reference the code for the
NAR()?????? ?? ??? ???? ???.:
private void NAR(object o)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(o);
}
catch {}
finally
{
o = null;
}
}
?????? ??????
Note that if you follow the steps that are described in the
"Steps to Reproduce the Behavior" section, and the server still does not shut
down, you can use the
GC.Collect()???? ??
GC.WaitForPendingFinalizers()method after you release the last object. Because the runtime
performs garbage collection on the RCW, the
GC.Collect()method forces the garbage collector to run and might release any
references that the RCW still has. The
GC.Collect()method tries to reclaim the maximum memory that is available. ????? ??? ?? ?? ?????? ???? ?? ??? ?????? reclaimed ?? ??????
???? ID: 317109 - ????? ???????: 04 ?????? 2010 - ??????: 2.0
???? ???? ???? ??:
- Microsoft Visual Basic .NET 2003 Standard Edition
- Microsoft Visual C# .NET 2003 Standard Edition
- Microsoft Visual Basic .NET 2002 Standard Edition
- Microsoft Visual C# .NET 2002 Standard Edition
| kbautomation kbprb kbmt KB317109 KbMthi |
???? ?????? ??????????????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:
317109
(http://support.microsoft.com/kb/317109/en-us/
)