C#注册两个事件,但只有一个反应,请帮助我 [英] C# Register Two Events, but only one reaction, please help me

查看:100
本文介绍了C#注册两个事件,但只有一个反应,请帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的大家,

我目前正在开发GPS跟踪软件.如果GPS进入特定区域并在超出边界后停止记录,则应实现触发GPS数据记录的功能.

无论如何,我的问题是,如果我选择GPS作为可观察对象并创建GPSMonitor类来监视其状态.我注册了两个基于gpsmonitor的事件,发现如果GPS进入边界区域,则日志记录功能有效,但另一个事件从未触发.我认为我的编程技能存在一些问题.

我是这样注册我的GPS监视器的:

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);



然后我附加了两个事件,一个事件是gps进入特定区域时发生的,另一事件是gps超出地理围栏时发生的.



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);


和gpsmonitor由
开始


and gpsmonitor start by

gpsmonitor.GeofenceSDetermination();



以下两个部分是两个事件发生的方法.

当GPS进入该区域时,以下部分可以很好地发挥作用:



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));
}



我认为在我的条件下确定进入或退出GPS的可能性较小,因为我已经对其进行了测试.我不知道事件注册是否存在问题.

非常感谢大家的建议和指导.



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.

推荐答案

这是错字吗?

Is this a typo?

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

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



如果没有,那就是您的错误.



If not, there''s your bug.


这篇关于C#注册两个事件,但只有一个反应,请帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆