1
votes

Very simple repro app - created a new Windows Phone 8 C# app from template in Visual Studio, added an Image to the content panel, then subscribed for NDEF proximity messages as shown:

// Constructor
    public MainPage()
    {
        InitializeComponent();

        ProximityDevice device = ProximityDevice.GetDefault();
        if (device != null)
        {
            device.SubscribeForMessage("NDEF", handler);
        }
    }

    private void handler(ProximityDevice sender, ProximityMessage message)
    {
        Debug.WriteLine("Received message");
        Dispatcher.BeginInvoke(() =>
            {
                myImage.Source = new BitmapImage(new Uri("Assets/test.png", UriKind.Relative));
            });
    }

First event works fine (image source is changed successfully). However, after this event has fired once it no longer fires if I touch another NFC tag. If I remove the call to update the image source, it will fire on each touch.

I can't understand why there would be any interaction here. The phone I'm testing on is a Nokia Lumia 620.

1
Any explanation for the downvote would be appreciated...Chris Cooper

1 Answers

0
votes

Just a shot in the dark: try to keep reference to your ProximityDevice somewhere. Make it a member of the class and assign in constructor.

class MainPage : PhoneApplicationPage
{
    private ProximityDevice device;
    public MainPage()
    {
        InitializeComponent();

        device = ProximityDevice.GetDefault();
        if (device != null)
        {
            device.SubscribeForMessage("NDEF", handler);
        }
    }
    ...
}

As it correctly mentioned in comments, this is caused by the Garbage Collector, which collects the instance of the ProximityDevice. When new BitmapImage is created, memory consumption grows, and this triggers the GC process. That's why you don't have such issue when you don't create the image.