StackOverFlowException in Class Event

Hi,

I’m kind of new to Plugin-development and is trying to write a class which is doing some work and during the process sends an event back to RB2012r1.2.
The event looks like this from within RB:

Processing(BytesProcessed as Integer, BytesToProcess as Integer)

The problem is that I run into a StackoverflowException and I do not know why. It seems as if the callback to RB has been performed a couple of times I get the exception.

Dan

Here’s some code snippets that shows what I’m doing.

REALevent DansClassEvents[] = {
{ “Processing( BytesProcessed as Integer, BytesToProcess as Integer )”},
};

void FireProcessingEvent( REALobject instance, long NumOfBytes,long NumOfTotalBytes )
{
void (fpProcessing)(REALobject instance, long i,long ii) =
(void (
)(REALobject, long,long))REALGetEventInstance( (REALcontrolInstance)instance, & DansClassEvents[ 0 ] );

if (fpProcessing) {
	fpProcessing( instance, NumOfBytes , NumOfTotalBytes);
} else {
	return;
}

}

FireExpandingEvent(instance,completedBytes,totalBytes);

This often happens if plugin calls event on a thread which was not created by Xojo.

So if I’m calling a function which runs threaded in another environment this might happen?

Is there a work-around for this situation?

set a flag, check on main thread the flag and fire event there?