0

I'm writing an application that involves both RFID & barcode scanners. I'm trying to create a class for the RFID scanner & keep getting this &%#$* error.

Here's the relevant code:

Private Dispatcher As Dispatcher
Private Delegate Sub TimerDispatcherDelegate()

...

  '[Constructor]
    'Start timer
    timer = New System.Timers.Timer()
    AddHandler timer.Elapsed, AddressOf timer_Elapsed
    timer.Interval = 1000
    timer.Enabled = True
  End If

End Sub


Private Sub timer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)

  'Delegate handler for timer events
  ***NEXT LINE THROWS THE ERROR- Me.Dispatcher is not set to an instance of an object***
  Me.Dispatcher.Invoke(Windows.Threading.DispatcherPriority.Normal, New TimerDispatcherDelegate(AddressOf timer_WorkItem))

End Sub


Private Sub timer_WorkItem()

  'Populate reader struct
  ReaderState.Name = ReaderName
  ReaderState.CurrentState = SmartCard.SCARD_STATE_UNAWARE
...

I'm stumped. If I take out the Dispatcher declaration, I get a "Me.Dispatcher is not a member" error.

However, I'm (shamelessly) pinching code from a manufacturer's demo application & it uses the same timer_Elapsed(...) code- with no Dispatcher declaration in the project- and runs just fine.

Any thoughts?

  • Where is `Dispatcher` initialized...? – Mark Dec 19 '14 at 19:24
  • `Private Dispatcher As Dispatcher` simply declares a variable, you also need to create an instance of it using `New`. It is a very bad idea to use a Type Name as a variable name, you should use `myDisplatcher` or similar – Ňɏssa Pøngjǣrdenlarp Dec 19 '14 at 19:31
  • @Mark- it's initialized up at the top of the class; if I don't initialize it, I get the "Me.Dispatcher is not a member" error. – Ron Fost Dec 22 '14 at 15:57
  • @Plutonix- I've tried that, too; it throws an error that the Dispatcher object doesn't have a constructor. And it doesn't matter what I name it, I still get the NullReferenceException (generally, I agree with you about naming; I'm just trying to get this bloody timer to work). – Ron Fost Dec 22 '14 at 16:00

0 Answers0