How to do SetEvent/CreateEvent in VB .Net

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have this C++ code I'm trying to port to VB .Net:
HANDLE g_hImageReady = NULL; // Event for when image is ready to transfer
//
// Initialize the globals
//
g_hImageReady = CreateEvent(NULL, TRUE, FALSE, NULL);
if(g_hImageReady == NULL)
{
printf("Unable to create image ready event. Exiting...\n");
continue;
}

And later:
if( (inEvent == KPDCAddFile) || (inEvent == KPDCFolderContent) )
{
SetEvent(g_hImageReady);
}

The CreateEvent and SetEvents are what I need to replicate. I'm not sure
exactly what they are used for and what their equivelent would be. I have
done delegates in VB .Net. Is this related?
 
M K said:
I have this C++ code I'm trying to port to VB .Net:
HANDLE g_hImageReady = NULL; // Event for when image is ready to transfer
//
// Initialize the globals
//
g_hImageReady = CreateEvent(NULL, TRUE, FALSE, NULL);
if(g_hImageReady == NULL)
{
printf("Unable to create image ready event. Exiting...\n");
continue;
}

And later:
if( (inEvent == KPDCAddFile) || (inEvent == KPDCFolderContent) )
{
SetEvent(g_hImageReady);
}

The CreateEvent and SetEvents are what I need to replicate. I'm not sure
exactly what they are used for and what their equivelent would be. I have
done delegates in VB .Net. Is this related?

see
System.Threading.ManualResetEvent
and
System.Threading.AutoResetEvent

David
 
I'm thinking you're on to something. Okay, here is more of my issue. (I have
a post on channel9. http://channel9.msdn.com/ShowPost.aspx?PostID=33171)

I have a form with an instance of a class (DCSIntf). DCSIntf wraps unmanaged
code. The unmanaged code calls a function in DCSIntf on certain events. My
function in DCSIntf raises an event that is handled by my form. The function
in DCSIntf fires, but only once. The subsequent calls don't fire until my
form closes. By then the wrapper class is GC'd so the unmanaged calls error.
 
So, do I do:
Private g_hImageReady as ManualResetEvent
g_hImageReady = new ManualResetEvent(False)

?

Please, I'm down to the wire... this is the last piece.
 
I'm not sure what to do with what you said. It seems like it would help, but
this is a new concept. Any help would be greatly appreciated, as the deadline
for this project is tomorrow.
 
Back
Top