# PC SDK - exception while reading RAPID data

**URL:** <https://tech-community.robotics.abb.com/t/pc-sdk-exception-while-reading-rapid-data/5212>\
**Category:** Developer Tools\
**Created:** [November 15, 2012, 2:10pm UTC](https://tech-community.robotics.abb.com/t/pc-sdk-exception-while-reading-rapid-data/5212 "2012-11-15T14:10:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alamaison](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@alamaison](https://tech-community.robotics.abb.com/u/alamaison)\
**Post date:** [November 15, 2012, 2:10pm UTC](https://tech-community.robotics.abb.com/t/pc-sdk-exception-while-reading-rapid-data/5212/1 "2012-11-15T14:10:32Z")

</div>

I’m working with PC SDK 5.14, and i’m trying to make a software in C# which receive and send some data to an ABB Controller.

In my software, i wrote some code to register to an event when one of the rapid value change. Then I read this value and send it to the rest of my code.

```auto

private bool registerRapidDataEvents()
{
RapidData rd = controller.Rapid.GetTask("T_ROB1").GetModule("LASER")
.GetRapidData("LASER_MODE");
rd.ValueChanged += new EventHandler<DataValueChangedEventArgs>
(laserLaserMode_ValueChanged);
rd.Dispose();

return true;
}

private void laserLaserMode_ValueChanged(object sender, DataValueChangedEventArgs e)
{
if (this.callbackObject != null && this.controller != null)
{
RapidData rd = null;
try
{
rd = controller.Rapid.GetTask("T_ROB1")
.GetModule("LASER")
.GetRapidData("LASER_MODE");
IRapidData data = rd.Value;
if (data is ABB.Robotics.Controllers.RapidDomain.Byte)
{
ABB.Robotics.Controllers.RapidDomain.Byte value =
(ABB.Robotics.Controllers.RapidDomain.Byte)data;
OnLaserModeChanged((int)value);
}
}
catch (ABB.Robotics.BaseException ex)
{}
finally
{
if (rd != null)
rd.Dispose();
}
}
}

```

My problem is that one exception of type “System.Threading.ThreadAbortException” is send by ABB.Robotics.Adapters.IRC5.dll  
This exception occur when I execute, in the event callback function, the line :

```auto
IRapidData data = rd.Value;
```

I don’t know what I’m doing wrong because I succesfully register the event without any problem.

For debugging purpose I wrote some code in RobotStudio which is running in a virtual robot :

```auto

MODULE LASER
PERS byte LASER_MODE:=1;

PROC main()
While true DO
IF LASER_MODE<8 THEN
LASER_MODE := LASER_MODE + 1;
ELSE
LASER_MODE := 0;
ENDIF
WaitTime 5;
ENDWHILE
ENDPROC
ENDMODULE

```

---

<div class="post-metadata">

**Author:** ![baldwindc](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/baldwindc/32/4376_2.png) [@baldwindc](https://tech-community.robotics.abb.com/u/baldwindc)\
**Post date:** [September 5, 2013, 1:27pm UTC](https://tech-community.robotics.abb.com/t/pc-sdk-exception-while-reading-rapid-data/5212/2 "2013-09-05T13:27:51Z")

</div>

Probably not a complete fix, but remove your call to “rd.dispose()”

You’re going to be using the variable for the duration of the class since you set up an event handler.
