代码之家  ›  专栏  ›  技术社区  ›  Paul Farry

为什么.NET Framework 2.0上缺少AutoresetEvent.WaitOne重载

  •  3
  • Paul Farry  · 技术社区  · 16 年前

    如果您遇到了一个异常情况,有些机器似乎在很长一段时间内没有应用Windows更新,而.NET Framework 2.0中没有可用的特定重载。

    如果您调用AutoResetEvent.WaitOne(int32,boolean),就可以了。

    当您调用此方法时,它会导致应用程序完全崩溃,而不会捕获异常等。

    我想出了一个解决方法,但想知道人们是如何鼓励他们的用户将机器更新到最新的service Pack等的。?

    最好接受他们不会相应地更新和编码,或者通过不让程序启动来强制他们更新。

    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
    
    2 回复  |  直到 16 年前
        1
  •  5
  •   o.k.w    16 年前

    如果我没有错的话,重载方法是在.NET2.0SP2中引入的。

    如果您参考.NET 2.0中该方法的特定MSDN参考,则不会列出新的重载方法。NET3.5/4.0确实有。

    AutoResetEvent .NET 2.0 on MSDN
    AutoResetEvent .NET 3.5 on MSDN

    以下是一篇相关文章:

    MissingMethodException and WaitOne

        2
  •  4
  •   Pent Ploompuu    16 年前

    AutoResetEvent.WaitOne(int32, boolean) 使用第二个参数 exitContext = false

    推荐文章