2011-11-29 102 views
0

我正在運行此VB.NET代碼來將WAV文件轉換爲mp3。它通常每小時運行20次。隨機地,大約每天一次,應用程序池掛在objMP3 = CreateObject("AudioConverter.AudioConverterx")上。重新啓動應用程序池可以修復它。CreateObject導致App Pool掛起

'convert the file 
objMP3 = CreateObject("AudioConverter.AudioConverterx") 
objMP3.Logfile = myLogFileName 
objMP3.Convert(myWAVfile, myMP3file, "-cMP3") 
objMP3 = Nothing 

每次發生這種情況,事件日誌中有這樣的錯誤:

Faulting application w3wp.exe, version 6.0.3790.3959, stamp 45d6968e, faulting module audioconverter.dll, version 0.0.0.0, stamp 2a425e19, debug? 0, fault address 0x0000402e.

同時系統日誌有這樣的:

A process serving application pool 'tts.servername.com' exceeded time limits during shut down. The process id was '1340'.

,我能想到的唯一的事情是,該應用程序未被正確關閉。我讀過objMP3 = Nothing並沒有真正關閉它(或者它與傳統的vb不一樣)。

我也在服務器上設置了調試診斷。發生掛起時,每秒會創建一個大文件(> 8GB),並且每次只有該行多次。

[11/8/2011 9:28:36 PM] First chance exception - 0xc0000005 caused by thread with System ID: 2548

任何想法?

+0

那COM服務器只需訪問衝突崩潰。本機代碼很漂亮的失敗模式。您需要調試它或將其丟棄。 –

回答

0

爲了從.NET正確發佈COM對象,並確保它的終結器運行,您應該調用Marshall.ReleaseComObject

這是我使用的代碼:

'convert the file 
    objMP3 = CreateObject("AudioConverter.AudioConverterx") 
    ' Do stuff 
    ReleaseComObject(objMP3) 

    private void ReleaseComObject(object o) 
    { 
     try 
     { 
      if (o != null) 
      { 
       // As per the documentation, call ReleaseComObject in a loop 
       // until all references are released. 
       while (System.Runtime.InteropServices.Marshal.ReleaseComObject(o) > 0) 
       { 
       } 
      } 

      o = null; 
     } 
     catch (System.Runtime.InteropServices.COMException) 
     { 
      // Do nothing. We don't want exceptions to leak out of this method. 
     } 
    }