Solved

C# updating controls using events from another class

Posted on 2010-11-10
6
768 Views
Last Modified: 2013-12-27
Hey guys,

i'm basically trying to use an event defined in another class to update a control in a separate class, no errors, but the event doesn't seem to be firing, I'm obviously doing something wrong but just don't know what.
public class GPSCommand

{

    public GeoCoordinateWatcher GeoWatcher;



    public event EventHandler<GeoPositionStatusChangedEventArgs>

    GeoWatcher_Status;



    public void StartGeoWatcher()

    {

            

        if (GeoWatcher == null)

        {

            GeoWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);

 

            GeoWatcher.MovementThreshold = 20;



            GeoWatcher.Start();



        }



    }



}



// And then the class with the event handler function...



public partial class MainPage : PhoneApplicationPage

{

    private GPSCommand GPS = new GPSCommand();



    private void MainPage_Loaded(object sender, RoutedEventArgs e)

    {

        // Get current position..

        GPS.StartGeoWatcher();

        GPS.GeoWatcher_Status += new EventHandler<System.Device.Location.GeoPositionStatusChangedEventArgs>(GPS_GeoWatcher_StatusChanged);

        }



        // Event handler for the GeoCoordinateWatcher.StatusChanged event.

        private void GPS_GeoWatcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)

        {

            switch (e.Status)

            {

                case GeoPositionStatus.Disabled:

                    // The Location Service is disabled or unsupported.

                    // Check to see if the user has disabled the Location Service.

                    if (GPS.GeoWatcher.Permission == GeoPositionPermission.Denied)

                    {

                        

                        // The user has disabled the Location Service on their device.



                        tbStatus.Text = "you have this application access to location.";

                    }

                    else

                    {

                        tbStatus.Text = "location is not functioning on this device";

                    }

                    break;



                case GeoPositionStatus.Initializing:

                    tbStatus.Text = "Initializind data location service...";

                    //startLocationButton.IsEnabled = false;

                    break;



                case GeoPositionStatus.NoData:

                    tbStatus.Text = "location data is not available.";

                    //stopLocationButton.IsEnabled = true;

                    break;



                case GeoPositionStatus.Ready:

                    tbStatus.Text = "location data is available.";

                    //stopLocationButton.IsEnabled = true;

                    break;

            }

        }

    }

Open in new window

0
Comment
Question by:aarmstr2
  • 4
  • 2
6 Comments
 
LVL 24

Accepted Solution

by:
alexey_gusev earned 500 total points
Comment Utility
sorry for being dumb :) , but where's the code where you actually fire the event in your 1st class code? something like

...
if (GeoWatcher_Status != null)
     GeoWatcher_Status();
...
0
 
LVL 1

Author Comment

by:aarmstr2
Comment Utility
Doh, i can such a restard sometimes! Changed this line as follows;-

GPS.GeoWatcher_Status += new EventHandler<System.Device.Location.GeoPositionStatusChangedEventArgs>(GPS_GeoWatcher_StatusChanged);

to....

GPS.GeoWatcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(GPS_GeoWatcher_StatusChanged);

Works now... :S
0
 
LVL 1

Author Closing Comment

by:aarmstr2
Comment Utility
For making me think!
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 1

Author Comment

by:aarmstr2
Comment Utility
btw, do u really think my code was 1st class or were u being sarcastic?
0
 
LVL 24

Expert Comment

by:alexey_gusev
Comment Utility
ah, all I meant is to save on typing the class name, sorry :) , so it was as in "your first class" :)
0
 
LVL 1

Author Comment

by:aarmstr2
Comment Utility
lol
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article shows how to setup the internet connectivity on Windows Mobile Emulator.   I assume that you already have Microsoft Visual Studio, Microsoft Windows Mobile SDK's and the emulator installed. The emulator is available with Visual Studi…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now