Why is there no AutoresetEvent.WaitOne overload in the .NET Framework 2.0

If an anomaly occurs when it seems that on some machines that did not have Windows Update, for a VERY long time when the .NET Framework 2.0 did not have the specific overload available in it.

AutoResetEvent.WaitOne (int32) does not seem to exist in the earlier version. According to MS documentation, this method has always been there, but obviously it is not. If you call AutoResetEvent.WaitOne (int32, boolean), this is normal.

When you call this method, it causes the application to crash completely without any chance of catching an exception, etc.

I came up with a workaround for him, but wondered how people encourage their users to update their computers to the latest service packs, etc.?

Is it better to accept that they will not be updated and encoded accordingly, or force them to be updated without starting the program.

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
+3
source share
2 answers

If I am not mistaken, the overload method was introduced in .NET 2.0 SP2.

If you are referencing a specific MSDN link for this method for .NET 2.0, a new overload method is not specified. .NET 3.5 / 4.0 has this.

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

Here is a related article:

MissingMethodException and WaitOne

+5
source

I think that the most sensible solution is always to call AutoResetEvent.WaitOne(int32, boolean)with the second parameter exitContext = false.

+4
source

Source: https://habr.com/ru/post/1730487/


All Articles