Wed, November 10, 2004, 09:29 PM under
Links
Testing if
this works in blogger
C# (btw, for the full MsgQueue API set look
here)
/// <summary>
/// This function opens a handle to an existing message queue based on
/// a message queue handle.
/// </summary>
/// <param name="hSrcProc">[in] Handle to a source process that owns the
/// hMsgQ message queue handle. </param>
/// <param name="hMsgQ">[in] Handle to a message queue returned by the
/// CreateMsgQueue function.</param>
/// <param name="lpOptions">[in] Pointer to an MSGQUEUEOPTIONS structure
/// that sets the properties of the message queue.</param>
/// <returns>Returns a handle to a message queue, or returns NULL if the
/// queue could not be opened.</returns>
[DllImport("coredll.dll", SetLastError=true)]
public static extern IntPtr OpenMsgQueue(IntPtr hSrcProc, IntPtr hMsgQ,
MsgQueueOptions lpOptions);
VB (btw, this is a another example of
this)
Private Function DoWork2() As Boolean
' If I don't have a requester then I can't do anything with the input
' so ignore it (and don't obtain the lock!)
Dim req As ForMyPending = Nothing
req = Me.FindFreeRequester
If req Is Nothing Then
Return False
End If
' Get the next object from the queue
Dim queObj As ForMyQueue = Nothing
SyncLock mQue.SyncRoot
If mQue.Count > 0 Then
queObj = DirectCast(mQue.Dequeue(), ForMyQueue)
End If
End SyncLock
' Deal with the next object from the queue without holding the lock!
If Not queObj Is Nothing Then
If queObj.ReqArgs.MaxNumResponses <> 0 Then'chance for client to cancel
req.Deleg = queObj.Deleg
If req.Requester.Request(queObj.ReqArgs, queObj.State) = False Then
If Not req.Deleg Is Nothing Then
req.Deleg.Invoke(Me, ReplyArgs.Empty)'failed
req.Deleg = Nothing'otherwise it wil never be reused again!
End If
End If
End If
End If
Return True
End Function