C
Chris
Hi,
I think I'm having some problems here with garbage collection. Currently, I
have the following code:
public struct Event
{
public int timestamp;
public EventType event;
public short device;
public int status;
public int input;
}
and the following method using the above struct:
unsafe private void Message( int msg )
{
Event myEvent = new Event();
while ( GetEvent(myEvent) != -1 )
{
// do some work
}
}
GetEvent is a call to an external DLL written in C++. When I send the
myEvent reference to the DLL, I receive a 'System.NullReferenceException'.
I believe this is because that myEvent gets garbage collected shortly after
the function call to the dll. Am I correct? How do I prevent the struct
(or reference to the struct) from being garbage collected until after the
function call is complete?
Thanks in advance,
Chris
I think I'm having some problems here with garbage collection. Currently, I
have the following code:
public struct Event
{
public int timestamp;
public EventType event;
public short device;
public int status;
public int input;
}
and the following method using the above struct:
unsafe private void Message( int msg )
{
Event myEvent = new Event();
while ( GetEvent(myEvent) != -1 )
{
// do some work
}
}
GetEvent is a call to an external DLL written in C++. When I send the
myEvent reference to the DLL, I receive a 'System.NullReferenceException'.
I believe this is because that myEvent gets garbage collected shortly after
the function call to the dll. Am I correct? How do I prevent the struct
(or reference to the struct) from being garbage collected until after the
function call is complete?
Thanks in advance,
Chris