Visual Studio .NET ??????? ?? ??????? ?? ??? Office ????????? ?? ???? ????

???? ?????? ???? ??????
???? ID: 317109 - ?? ???????? ?? ?????? ??? ?? ?? ???? ???? ???? ??.
??? ?? ??????? ???? | ??? ?? ??????? ????

?? ????? ??

?????

?? ?? ???? 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 ????????? ???????? ?? ?????? ???

??????

?? ??????? ??????? ?????? ??..

???? ???????

??????? ?? ???: ??????? ???? ?? ??? ???

  1. Visual Studio .NET ?? ??????? ?????
  2. ????? ???????????? ??,????? ????-????? ????, ?? ???? ????????????. ?? ???????Visual Basic ???????????? ????Windows ??????????? ????? ????OK. Form1 ???????? ??? ?? ???? ??..
  3. ???? ?????? ??????Microsoft Excel ???????? ?????????. ??? ???? ?? ???, ????? ????? ?? ???? ????::
    1. ????? ????????????????? ??,?????? ??????.
    2. ????? ????COM??? ???, Excel ?? ??? ???????? ????????? ?? ?????? ?????, ?? ???? ??? ????? ??????? ????.

      Microsoft Excel 2002: ?? ???Microsoft Excel 10.0 ???????? ?????????

      ???:??? ???? ??? ??? ?? ????, ?? ???????? ?? ?? ?? ??????? ???? ?? Microsoft Office XP ???????? Interop Assemblies (PIAs) ?? ??????? ?????Office XP PIAs ?? ???? ??? ???????? ??????? ?? ??? Microsoft ???????? ??? ???? ????? ?? ??? ????? ???? ?????? ?? ????? ????:
      328912Microsoft Office XP ???????? ?????? assemblies (PIAs) ??????? ???? ?? ??? ?????? ???
      Microsoft Office Excel 2003: ?? ???Microsoft Excel 11.0 ???????? ?????????
    3. ????? ????,OK??????????? ??????????? ????? ???? ??? ?? ??????? ???? ?? ??? ???
  4. ????? ????????????? ??,????? ?????, ?? ??? ????? ?????Form1 ?? ????????? ?????
  5. ???-????? ????Button1. ?????? ?? ??? ??? ????? ????? ????..
  6. ????? ??? Form1.vb ?? ???? ??? ??? ??????:
    Imports Microsoft.Office.Interop
    					
  7. ??? ????? ??? ????? ??? ?? ???????????? ????
        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
    					
  8. ????????? ?? ????? ?? ??? F5 ??????
  9. Windows ????? ??????? ?????? Visual Studio ??? ???? ????? ????? ?? ??? ?????? ????? ????????? ????? ???? ??? ????? ???? ?? ??? ???? ?? Excel.exe ?? ??????? ??? ????? ????????????????? ????
  10. Excel ?? ?????? ??? ?? ???? ????? ???? ??? ?? ?? ?? sleeping ????????? ?? ???? ??? ????? ????? ??? ???? ?? ??? ???? ?? Excel ?? ??? ????? ???? ????????????????? ????
  11. ?? ?? ??? "??????" ??? ??? ??????????? ?? ??, ?? 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 theNAR()?????? ?? ??? ???? ???.:
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 theGC.Collect()???? ??GC.WaitForPendingFinalizers()method after you release the last object. Because the runtime performs garbage collection on the RCW, theGC.Collect()method forces the garbage collector to run and might release any references that the RCW still has. TheGC.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

??????????? ???

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com