?? ??? ????? ????? office ??? ????? ?? Visual Studio.net ??????

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

?? ??? ??????

???????

??? ????? ??? ??????? Microsoft Office ?? .NET Visual Basic Microsoft ?? Microsoft Visual C#.net? ????? Office ?? ??? ????? ??? ??????? ??????? Quit .

?????

????? ???? ????????? Visual Studio.net COM ?? ????? ????????? ????????? ???? ???????? ?????? ??? ??????? ????????? ?????? (RCW). RCW ???? ????????? ??? ???????.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 ?? ???? ??? ???? ?????? 0 ??? ???????? ?? ??????? ????. ????? System.Runtime.InteropServices.Marshal.ReleaseComObject ????? ??? ???? RCW? ??? ?????? ???? ?????? ?? ?? ???? COM ??????? ?? ??? ????? ?? ??? ???? ????? ??? ???? CLR.
  • ?????? ??????? ??? ???????? ?? ?????? ????? ????? ?? ??? ?? Null.
  • ??????? ?? ?????? ????? ?????? ????? Office ?????? ?????? ??? ????? ?????.

?????

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

??????? ????

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

  1. ??? ????? Visual Studio.net.
  2. ?? ??????? ??? ? ???? ??? ???? ??? ?? ???? ??? ???????. ??? ?????? Visual Basic? ??? ????? Windows ????? ??? ?????. ??? ????? Form1 ???? ???????.
  3. ?? ?????? ???? ??? ???? Microsoft Excel ?????. ?????? ????? ???? ??????? ???????:
    1. ?? ??????? ??????? ???? ??? ????? ????.
    2. ??? ????? ??????? " COM "? ????? ???? "????? ??????" ? Excel? ??? ?? ???? ??? ?????.

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

      ?????? ??? ???? ?? ???? ???? ??? ???????? ?? ???? ????? ?????? Microsoft Office XP ???????? ??????? ??????? ???????? ????????? (PIAs). ?????? ??? ??????? ?????? ??? Office XP PIAs? ???? ??? ??? ??????? ?????? ???? ??????? ?? ????? ????? Microsoft:
      328912Microsoft Office XP ??????? ??????? ???????? (PIAs) ??? ?????? ???????
      ????? ?????? Microsoft Excel 11.0 ? Microsoft Office Excel 2003:
    3. ???? ??? ????? ?? ???? ?????? ????? ????? ????? ?????????.
  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 ?? ???? ???? ?? ????? ?????? ??? ??? ?????? ??????? ?????. ????? ???? ?????? ????? ?? ?? ??? ???? Excel ?? ????? ???????? .
  11. ??? ????? ??????? ???????? ?? ??? "????"? ????? ????? Office ??? ??? ??????? ??????? ??????. ??????? ?????? ?? ?????? 5 ?? ????????? ???????? ???????:
      Private Sub NAR(ByVal o As Object)
        Try
          While (System.Runtime.InteropServices.Marshal.ReleaseComObject(o) > 0)
          End While
        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
    					
??? ??? ?????? Visual C#.net? ??????? ??? ??? ?????? NAR() :
private void NAR(object o)
{
    try 
    {
        while (System.Runtime.InteropServices.Marshal.ReleaseComObject(o) > 0) ;
    }
    catch {}
    finally 
    {
        o = null;
    }
}
??????: ????? ??.net Framework 2.0? ????? ??????? System.Runtime.InteropServices.Marshal.FinalReleaseComObject ????? ?? ????? ????? ???? ?????? ??????? System.Runtime.InteropServices.Marshal.ReleaseComObject ?????? ??? ???????.

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

???? ??? ?? ???? ????? ??????? ??????? ?? ????? "????? ?????? ?????? ????? ??????" ??????? ?? ???? ?? ???? ??? ??????? ????? ??????? GC.Collect()GC ????????.WaitForPendingFinalizers() ??????? ??? ????? ???? ???. ??? ??? ??????? ???? ?????? ???????? ??????? ??? RCW GC.Collect() ???? ???? ?????? ??????? ????? ????? ?? ?? ????? RCW ?? ??? ????. GC.Collect() ????? ??????? ???????? ???? ?????? ??????? ????????. ???? ?? ??? ?? ???? ??? ???? ??????? ?? ???????.

???????

???? ???????: 317109 - ????? ??? ??????: 15/?????/1433 - ??????: 1.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 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????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