Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0 delegates event
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
gpsmonitor.GeofenceSDetermination();
 
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
Edited 2-Nov-11 10:31am
v3

1 solution

Rate this: bad
good
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.
  Permalink  
v3
Comments
HAOYE850815 at 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 at 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 at 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 at 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 at 2-Nov-11 17:09pm
   
Congratulations - this was your answer number 1000 :)
HAOYE850815 at 2-Nov-11 17:13pm
   
Sorry, I am not fully understand- what is the answer number?
Espen Harlinn at 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 at 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
0 Sergey Alexandrovich Kryukov 520
1 OriginalGriff 339
2 ChintanShukla 305
3 Richard Deeming 235
4 RyanDev 230
0 Sergey Alexandrovich Kryukov 8,858
1 OriginalGriff 7,451
2 CPallini 2,603
3 Richard MacCutchan 2,095
4 Abhinav S 1,893


Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 2 Nov 2011
Copyright © CodeProject, 1999-2014
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