This is a question re: a mobile development project, however I feel my issue is C# based and not anything to do with the mobile side of thigs, so I will leave this post here (as I feel it'll get a better responce)
Right... here we go:
I have an application based on a MS Sample for using GPS on a PDA. It works fine! (Woohoo!) It is using the Microsoft.WindowsMobile.Samples.Location project classes as it's base. These classes use multithreading
Expand|Select|Wrap|Line Numbers
- // Create and start thread to listen for GPS events
- gpsEventThread = new System.Threading.Thread(new System.Threading.ThreadStart(WaitForGpsEvents));
- gpsEventThread.Start();
Expand|Select|Wrap|Line Numbers
- private EventHandler updateDataHandler;
- Gps gps = new Gps();
- GpsPosition position = null;
- GpsDeviceState device = null;
- ......
- private void menuItem2_Click(object sender, EventArgs e)
- {
- try
- {
- Invoke(updateDataHandler);
- }
- .......
- private void Form1_Load(object sender, EventArgs e)
- {
- updateDataHandler = new EventHandler(updateData);
- label1.Text = "";
- gps.DeviceStateChanged += new DeviceStateChangedEventHandler(gps_DeviceStateChanged);
- gps.LocationChanged += new LocationChangedEventHandler(gps_LocationChanged);
- }
- void gps_LocationChanged(object sender, LocationChangedEventArgs args)
- {
- position = args.Position;
- }
- void gps_DeviceStateChanged(object sender, DeviceStateChangedEventArgs args)
- {
- device = args.DeviceState;
- }
- void updateData(object sender, System.EventArgs args)
- {
- Cursor.Current = Cursors.WaitCursor;
- if (gps.Opened)
- {
- string str = "";
- if (device != null)
- {
- str = device.FriendlyName + " " + device.ServiceState + ", " + device.DeviceState + "\n";
- }
- else
- {
- fullData = false;
- }
- if (position != null)
- {
- if (position.LatitudeValid)
- {
- str += "Latitude (DD): \n " + position.Latitude + "\n";
- str += "Latitude (D,M,S): \n " + position.LongitudeInDegreesMinutesSeconds + "\n";
- myGPSData.Lattitude = position.Latitude.ToString();
- }
I want my GPS to be started on the login form opening, and be able to pull it's position whenever I want using a method off various forms, and close the GPS on the applcation exiting. So essentially have it running, fully functional in the background.
Sorry for such a long post, but I like to get my point accross clearly, and help with how I should do this?
Cheers,
Mark