locked
Problem in Invoking Event Handler in Visual Studio

    Question

  • I am working on a Windows app for NFC. I have tried all possible methods to invoke an Event Handler in Visual Studio 2013 and I have been unsuccessful!!! No matter what, the event handler is not getting invoked/called. I have gone through other code snippets and answers posted by various users. They have been of some help, but its not making my code work. Could anyone please describe the flow of creating an event handler from the basic step??
    Monday, October 27, 2014 5:54 AM

Answers

  • The important thing is they run in another thread.

    public sealed partial class MainPage : Page
        {
            private ProximityDevice proximitydevice;
            public MainPage()
            {
                this.InitializeComponent();
                proximitydevice = ProximityDevice.GetDefault();
                if (proximitydevice != null)
                {
                    proximitydevice.DeviceArrived += proximitydevice_DeviceArrived;
                    proximitydevice.DeviceDeparted += proximitydevice_DeviceDeparted;
                }
                else
                { msgtxt.Text = "No NFC Device"; }
            }
            async private void proximitydevice_DeviceDeparted(ProximityDevice sender)
            { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => WriteMessage("Departed")); }
    
            async private void proximitydevice_DeviceArrived(ProximityDevice sender)
            { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => WriteMessage("Arrived")); }
    
            private void WriteMessage(String message)
            { msgtxt.Text = message; }
    
            protected override void OnNavigatedTo(NavigationEventArgs e)
            {
                
            }
        }


    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

    Wednesday, November 05, 2014 10:08 AM

All replies

  • I don't quite understand the issue - could you describe step by step what you want your App to do?

    E.g:

    1. NFC Tag is detected
    2. data object is updated with location information
    3. data object fires event DataChanged
    4. UI updates with new Data

    It's also always a good idea to post the code with which you tried to achieve the desired results so the answer can be tailored to you actual use case.

    Monday, October 27, 2014 8:08 AM
  • I want my app to read an NFC tag when i tap it and display the contents of the tag (say a web address or a name). 
    Monday, October 27, 2014 8:10 AM
  • Hi ApoorvaN,

    As Oliver has said, you need to post more information to let us know the problem. Please refer to the following link to let it start. http://blogs.msdn.com/b/windowsappdev/archive/2013/04/18/develop-a-cutting-edge-app-with-nfc.aspx.

    If you have questions about programming in store app, you are welcome to post them here.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Wednesday, November 05, 2014 9:42 AM
    Moderator
  • The important thing is they run in another thread.

    public sealed partial class MainPage : Page
        {
            private ProximityDevice proximitydevice;
            public MainPage()
            {
                this.InitializeComponent();
                proximitydevice = ProximityDevice.GetDefault();
                if (proximitydevice != null)
                {
                    proximitydevice.DeviceArrived += proximitydevice_DeviceArrived;
                    proximitydevice.DeviceDeparted += proximitydevice_DeviceDeparted;
                }
                else
                { msgtxt.Text = "No NFC Device"; }
            }
            async private void proximitydevice_DeviceDeparted(ProximityDevice sender)
            { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => WriteMessage("Departed")); }
    
            async private void proximitydevice_DeviceArrived(ProximityDevice sender)
            { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => WriteMessage("Arrived")); }
    
            private void WriteMessage(String message)
            { msgtxt.Text = message; }
    
            protected override void OnNavigatedTo(NavigationEventArgs e)
            {
                
            }
        }


    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

    Wednesday, November 05, 2014 10:08 AM