views:

309

answers:

2

If have come across an anomaly where it seems that some machines that have not had a Windows Update applied to them in a VERY long time that the .NET Framework 2.0 didn't have a specific overload available in it.

AutoResetEvent.WaitOne(int32) appears to be non existant under an early revision. According to MS documentation this method has always been there, but obviously it isn't. If you call AutoResetEvent.WaitOne(int32, boolean) it's fine.

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

I have come up with a workaround for it, but wondered how people encourage their users to update their machines to the latest service packs etc.?

Is it best to accept that they won't update and code accordingly, or force them to update by not letting the program start.

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
+4  A: 

If I'm not wrong the overload method was introduced in .NET 2.0 SP2.

If you refer to the specific MSDN reference for that method for .NET 2.0, the new overload method is not listed. .NET 3.5/4.0 do have it.

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

Here's a related article:

MissingMethodException and WaitOne

o.k.w
+4  A: 

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

Pent Ploompuu
thanks yes, this is what i did, i just used the little snippet above to detect their version.. it's so hard to figure out what version is actually installed.
Paul Farry