2010-01-29 39 views
3

如果遇到異常情況,似乎有一些機器在很長一段時間內沒有應用Windows Update,而.NET Framework 2.0沒有可用的特定超載。爲什麼在.NET Framework 2.0上有一個Missing AutoresetEvent.WaitOne重載

AutoResetEvent.WaitOne(int32)在早期版本中似乎不存在。根據MS文檔,這種方法一直存在,但顯然不是。 如果你調用AutoResetEvent.WaitOne(int32,boolean)就沒問題。

當調用此方法會導致應用程序崩潰完全沒有捕獲異常等

我想出了它一個解決辦法的任何機會,但想知道人們如何鼓勵用戶更新他們的機器到最新的服務包等?

是否最好接受它們不會更新和編碼,或者不讓程序啓動來強制更新。

Dim au As System.Threading.AutoResetEvent 
au = New System.Threading.AutoResetEvent(False) 

Dim themethods() As MethodInfo 
themethods = au.GetType.GetMethods() 
Dim found As Boolean 

For Each m As MethodInfo In themethods 
    If String.Equals(m.Name, "WaitOne", StringComparison.OrdinalIgnoreCase) Then 
     Dim params() As ParameterInfo 
     params = m.GetParameters 
     If params.Length = 1 Then 
      If params(0).ParameterType Is GetType(Integer) Then 
       found = True 
       Exit For 
      End If 
     End If 
    End If 
Next 

Dim allowRun As Boolean = True 

If Not found Then 
    ApplicationLog.Write("This system is running an old version of the Microsoft .NET Framework, please update with Windows Update to prevent errors.") 
    If MessageBox.Show("This system is running an old version of the Microsoft .NET Framework, please update with Windows Update to prevent errors.", "Old Version of .NET Framework", MessageBoxButtons.OKCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2) = DialogResult.Cancel Then 
     allowRun = False 
    End If 
End If 
+0

你指的是什麼版本的.NET? – t0mm13b 2010-01-29 01:36:16

+0

對不起,發現這個問題,這是因爲我編譯的.net3.5有mscorlib過載,但.net 2.0沒有。錯過了MSDN doco中的小子菜單,切換到.net 2 – 2010-01-29 01:37:58

+0

,您已被原諒。微軟改變了mscorlib的公共接口,但沒有改變[AssemblyVersion]號碼。很淘氣。 – 2010-01-29 01:46:56

回答

4

我認爲最合理的解決方案是永遠只是調用AutoResetEvent.WaitOne(int32, boolean)與第二個參數exitContext = false

+0

謝謝是的,這就是我所做的,我只是使用上面的小片段來檢測他們的版本..很難弄清楚實際安裝的版本。 – 2010-01-29 01:55:22

相關問題