Gavin Hannah
Gavin Hannah

Reputation: 181

eventhandler delegate

i'm trying to create a timed event using the following code:

// SET UP A TIMER INTERVAL TO POLL INSTRUMENTS ONCE EVERY SECOND
DispatcherTimer^ timer = ref new DispatcherTimer;

timer->Tick += ref new Windows::Foundation::EventHandler<Object^>(this, &MainPage::Request_Data);

TimeSpan t;
t.Duration = 1000;
timer->Interval = t;
timer->Start();

I'm getting an error on this bit, specifically the &:

timer->Tick += ref new Windows::Foundation::EventHandler<Object^>(this, &MainPage::Request_Data);

The error is Invalid delegate initializer -- function does not match the delegate type.

Any ideas?

Upvotes: 0

Views: 327

Answers (1)

Gavin Hannah
Gavin Hannah

Reputation: 181

Ok, so my function I was passing to the EventHandler to be called was missing a few bits.

So I had declared this function as:

void MainPage::Request_Data(){

... stuff

}

which should have been declared as:

void MainPage::Request_Data(Platform::Object^ sender, Platform::Object^ e){

... stuff

}

Upvotes: 1

Related Questions