vb.netmultithreadingvisual-studioaddressof

Reference to a non-shared member threading


I have opened a project built with VS2010 in VS2017.

The code hasn't changed and the 2010 version built perfectly but when building with 2017 I get a 'Reference to a non-shared member requires an object reference' error with the following code.

Dim doCheck As New System.Threading.Thread(AddressOf Check_Form.checkList)
doCheck.SetApartmentState(ApartmentState.STA)
doCheck.Start(thisname & "~" & thisnum)

The 'AddressOf' part throws the error.

Has something changed in VS2017 or have I forgotten to amend something? It's been a while since I looked at this but I've got a new signing certificate and the System.Threading is imported as always.

The Check_Form.checkList sub is public but not shared but it never has been in the past and always ran ok.

Thanks.


Solution

  • It seems that Check_Form is type of that owner form. And therefore My.Forms.Check_Form.checkList was used with implicit call of Check_Form.checkList

    I'm not sure if version 2017 has some changes in reference priorities but try changing your code to

    Dim doCheck As New System.Threading.Thread(AddressOf My.Forms.Check_Form.checkList)
    

    to get explicit version of the same code. Current version might prefere type before My.Forms property.