Click here to Skip to main content
13,045,564 members (71,706 online)
Rate this:
Please Sign up or sign in to vote.
Dear guys,

I am currently working on a GPS tracking software. It should implement a function to trigger GPS data logging if GPS enter in a specific area and stop logging after going out of boundary.

Anyway, My problem is if I select GPS as a observable object and make a GPSMonitor class to monitor its status. I registered two events based on my gpsmonitor, I found that if GPS enter in the bounding area, the logging function works, but the other event never been triggered. I think there are some problems for my programming skills.

I registered my GPS monitor like this way:
GPSMonitor gpsmonitor = new GPSmonitor (_tempX, _tempY, corners, _Time, sct, polygonGeofence);

and I then attached two events to it, one happened when gps enter a specific area, while the other one happened if gps go out of geofence.
gpsmonitor.GeofencePositioned += new GPSMonitor.PositionInGeofenceEventHandler(RaiseInEvent);

gpsmonitor.GeofenceOutPositioned += new GPSMonitor.PositionInGeofenceEventHandler(RaiseOutEvent);

and gpsmonitor start by

The methods happened by two events are the following two sections.

this following part works well when GPS enter in the area:
 private void RaiseAlarmEvent(object sender, PositionInGeofenceEventArgs e)
   DemoServer.SendText("1", DemoServer.IndexOf(Socket));
   BtnRecordData.BeginInvoke(new System.EventHandler(BtnRecordData_Click));

but second event below part doesn't work. it should trigger the Stop Button stopping, but it nothing happened.
private void RaiseAlarmEvent(object sender, PositionInGeofenceEventArgs e)
   gpsmonitor.GeofenceOutPositioned -= new GPSMonitor.PositionInGeofenceEventHandler(RaiseInEvent)
   DemoServer.SendText("2", DemoServer.IndexOf(Socket));
   BtnRecordData.BeginInvoke(new System.EventHandler(BtnRecordStop_Click));

I think there is less possible problems on my condition to determine the entry or out of GPS because I have tested it. I donnot know if there is problems on event registration.

Many thanks if any of you could give me suggestions and guidance.
Posted 2-Nov-11 9:55am
Updated 2-Nov-11 10:31am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Is this a typo?

gpsmonitor.GeofenceOutPositioned += new GPSMonitor.PositionInGeofenceEventHandler(RaiseInEvent);
gpsmonitor.GeofenceOutPositioned += new GPSMonitor.PositionInGeofenceEventHandler(RaiseOutEvent);

If not, there's your bug.
HAOYE850815 2-Nov-11 16:35pm
I am so sorry, It is a typo mistake. I have changed it.

Could you please help me to have a look the event registration? I am not sure why only one event triggered. It bothered me for several days. Many thanks.
Nishant Sivakumar 2-Nov-11 16:37pm
If the event is not firing when it should, it may be because you are using the component incorrectly or perhaps even a bug in the library. Either way you should probably ask the guys who wrote/sold this component. They'd know best how to resolve this.
HAOYE850815 2-Nov-11 16:47pm
Actually I programmed the event for myself. The entry condition is all right when I have tested. Could you please tell if you can find any problems on the events, particularly the register. Is there any problem if I write two events using one same delegate.many thanks for your reply
Nishant Sivakumar 3-Nov-11 7:48am
You'll need to step through the code that fires the events and see what's causing it to not fire.
Espen Harlinn 2-Nov-11 17:09pm
Congratulations - this was your answer number 1000 :)
HAOYE850815 2-Nov-11 17:13pm
Sorry, I am not fully understand- what is the answer number?
Espen Harlinn 2-Nov-11 21:18pm
Nishant has now written 1000 answers to various questions here on the Q&A section. This is his answer number 1000.
Nishant Sivakumar 3-Nov-11 7:47am
Wow, sweet!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 2 Nov 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100