HighTechTalks DotNet Forums  

WaitForMultipleObjects in .net

Dotnet Framework (Interop) microsoft.public.dotnet.framework.interop


Discuss WaitForMultipleObjects in .net in the Dotnet Framework (Interop) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
AT
 
Posts: n/a

Default WaitForMultipleObjects in .net - 11-14-2005 , 08:17 AM






Hi All,
I wanted to use WaitForMultipleObjects in C#. Following is the
code:

[DllImport("kernel32.dll", SetLastError=true)]
static extern int WaitForMultipleObjects ( int nCount, ref IntPtr
[]lpHandles, int bWaitAll, uint dwMilliseconds);
....
IntPtr []HandleArray = new IntPtr[2];
HandleArray[0] = (IntPtr)m_iStopEventHandle;
HandleArray[1] = (IntPtr)m_iTimerHandle;
int iRet = WaitForMultipleObjects(2, ref HandleArray, 1, INFINITE);
....

I am getting -1 (Invalid handle) as the return value.
If I use the 2 handles( m_iStopEventHandle and m_iTimerHandle) then
WaitForMultipleObjects works fine.
Please let me know if I am doing anything wrong with the pinvoke.

Thanks in advance.
nachiket


Reply With Quote
  #2  
Old   
Ming Chen
 
Posts: n/a

Default Re: WaitForMultipleObjects in .net - 11-14-2005 , 09:35 AM






Hi,

Arrays are marshalled to pointers by default, so you don't have to add
"ref" in the parameter.

[DllImport("kernel32.dll")]
static extern uint WaitForMultipleObjects(uint nCount, IntPtr [] lpHandles,
bool bWaitAll, uint dwMilliseconds);

Hope this helps.

<nachiket_pict_2002 (AT) yahoo (DOT) co.in> wrote

Quote:
Hi All,
I wanted to use WaitForMultipleObjects in C#. Following is the
code:

[DllImport("kernel32.dll", SetLastError=true)]
static extern int WaitForMultipleObjects ( int nCount, ref IntPtr
[]lpHandles, int bWaitAll, uint dwMilliseconds);
...
IntPtr []HandleArray = new IntPtr[2];
HandleArray[0] = (IntPtr)m_iStopEventHandle;
HandleArray[1] = (IntPtr)m_iTimerHandle;
int iRet = WaitForMultipleObjects(2, ref HandleArray, 1, INFINITE);
...

I am getting -1 (Invalid handle) as the return value.
If I use the 2 handles( m_iStopEventHandle and m_iTimerHandle) then
WaitForMultipleObjects works fine.
Please let me know if I am doing anything wrong with the pinvoke.

Thanks in advance.
nachiket




Reply With Quote
  #3  
Old   
AT
 
Posts: n/a

Default Re: WaitForMultipleObjects in .net - 11-15-2005 , 07:13 AM



Thanks for the reply.
I have not used WaitHandle since I have created the event and the timer
using p-invoke


Reply With Quote
  #4  
Old   
AT
 
Posts: n/a

Default Re: WaitForMultipleObjects in .net - 11-15-2005 , 07:13 AM



Thanks for the reply.
I have not used WaitHandle since I have created the event and the timer
using p-invoke.

Regards,
Nachiket


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.