Re: Problems with WaitForMultipleObjects under C#

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



The ManualResetEvent doesn't expose an actual handle, but a pseudohandle, so
it cannot be waited on through a P/Invoke. If you want to use
WaitForMultipleObjects, you'll have to P/Invoke CreateEvent and use the
handle returned from it.

-Chris


"John Olbert" <someone@xxxxxxxx> wrote in message
news:4DA51027-1006-4ED7-9889-55C7E330BC86@xxxxxxxxxxxxxxxx
> Under WinCe Win32 we are experiencing problems with
> "WaitForMultipleObjects(DWORD nCount, CONST HANDLE* lpHandles, BOOL
> fWaitAll,
> DWORD dwMilliseconds )" being accessed from C#. It returns WAIT_FAILED
> and a
> call to GetLastError() returns 0x80000005 (Invalid pointer).
>
> We are trying to implement the function "WaitHandle.WaitAny(commands);"
> which is not available in Netcf. We are using and extending the OpenNetcf
> open source code.
>
> The top call in its own thread looks like this--
> ManualResetEvent [] commands = { channelEvent, killEvent };
> int eventThatFired = 0;
> bool keepGoing = true;
>
> while (keepGoing)
> {
> eventThatFired = Core.WaitForMultipleObjectsJ1(commands,false);
>
> The code we added in OpenNetcf looks like this--
> [CLSCompliant(false)]
> public static Int32 WaitForMultipleObjectsJ1(ManualResetEvent [] commands,
> bool WaitForAll)
> {
> Int32 Len=commands.Length;
> if(commands==null||Len==0)
> {return 0;
> }
> IntPtr[] handles=new IntPtr[Len];
> for(Int32 i=0;i<Len;i++)
> {
> handles[i]=commands[i].Handle;
> }
> return
> OpenNETCF.Threading.NativeMethods.WaitForMultipleObjects((uint)handles.Length,
> handles, WaitForAll, (uint)0xFFFFFFFF);
> }
> OpenNetcf uses this PInvoke--
> [DllImport("coredll.dll", SetLastError=true)]
> public static extern int WaitForMultipleObjects(uint nCount, IntPtr[]
> lpHandles, bool fWaitAll, uint dwMilliseconds);
> The symptom is that the call "
> Core.WaitForMultipleObjectsJ1(commands,false);" returns immediately with a
> return value of -1. This works back (using the GetLastError()) to the
> invalid
> pointer error code.
>
> Each ManualResetEvent instance does block properly if invoked usng the
> WaitOne() method which is implemented in Netcf as below--
> bool xbool=channelEvent.WaitOne();
>
> Any help would be appreciated on this problem.
>
> Thanks.
>
> --
> John Olbert
>


.