Unsubscribe events with custom gui

Tips and tricks for Adept ACE

Unsubscribe events with custom gui

Postby icerany » Sun Jul 17, 2016 6:31 pm

Hi All,

I'm making a gui and subscribe some IAceServer, IVpLinkedObject events.
The problem shows on "unsubscribe" those events when disconnecting or disposing.

Subscribing codes,
Code: Select all
/* Generating ace objects */
RemotingUtil.InitializeRemotingSubsystem(true, 0);
IAceServer aceServer = (IAceServer)RemotingUtil.GetRemoteServerObject(typeof(IAceServer), "ace", "localhost", RemotingUtil.DefaultRemotingPort);
IAceClient aceClient = new AceClient(aceServer);
aceClient.InitializePlugins(null);
IAdeptController ctrl = aceServer.Root["/SmartController/SmartController"] as IAdeptController;

/* Subscribe events */
aceServer.Shutdown += AceSrv_Shutdown;
aceServer.WorkspaceLoad += AceSrv_WorkspaceLoad;
aceServer.WorkspaceSaved += AceSrv_WorkspaceSaved;
aceServer.WorkspaceUnload += AceSrv_WorkspaceUnload;
aceServer.Root.ContentsChanged += AceSrv_ContentsChanged;

ctrl.CalibrationStateChanged += VpLinkObj_CalibrationStateChanged;
ctrl.EStopStateChanged += VpLinkObj_EStopStateChanged;
ctrl.MonitorSpeedChanged += VpLinkObj_MonitorSpeedChanged;
ctrl.NodeStateChanged += VpLinkObj_NodeStateChanged;
ctrl.PowerStateChanged += VpLinkObj_PowerStateChanged;


Unsubscribe codes,
Code: Select all
aceServer.Shutdown -= AceSrv_Shutdown;
aceServer.WorkspaceLoad -= AceSrv_WorkspaceLoad;
aceServer.WorkspaceSaved -= AceSrv_WorkspaceSaved;
aceServer.WorkspaceUnload -= AceSrv_WorkspaceUnload;
aceServer.Root.ContentsChanged -= AceSrv_ContentsChanged;

ctrl.CalibrationStateChanged -= VpLinkObj_CalibrationStateChanged;
ctrl.EStopStateChanged -= VpLinkObj_EStopStateChanged;
ctrl.MonitorSpeedChanged -= VpLinkObj_MonitorSpeedChanged;
ctrl.NodeStateChanged -= VpLinkObj_NodeStateChanged;
ctrl.PowerStateChanged -= VpLinkObj_PowerStateChanged;


I have checked that unsubscribe codes are triggered and not throw any exception.

If I unsubscribe event (I have checked to "-=" with events are ran and passed.) and restart my gui with new connection.
I will receive two or more triggered. For example, I'll receive twice MonitorSpeedChanged when monitor speed is changed.

How should I unsubscribe event properly?

Ace version : 3.6.3.2
icerany
 
Posts: 54
Joined: Wed Jun 26, 2013 5:52 am

Re: Unsubscribe events with custom gui

Postby Guenter Grass » Tue Aug 16, 2016 7:14 am

Hi,

sorry for the late answer but I have not been to the office for the last 4 weeks.

The code to subscribe and unsubscribe from the events look fine. So, you should not be seeing multiple events fired. We did a check on the code in the 3.6 series and the default code does not throw the monitor speed changed event twice. So, we suspect there is something else in your application code that might account for the double event.

Best Regards
Günter
Guenter Grass
 
Posts: 189
Joined: Thu Oct 16, 2008 4:34 am


Return to Adept ACE

Who is online

Users browsing this forum: No registered users and 2 guests

cron