DsSocket never happy when interrupted in Receive event 
Author Message
 DsSocket never happy when interrupted in Receive event

I've noticed that DsSocket works fine PROVIDED it is NOT interrupted
in any way while in its Receive event. For example, just a simple
lstBox.Clear is enough to throw it completely. It just seems to lose
sync with the newsserver.

Anyone know (before I start experimenting) whether this is just a fact
of life with Winsock-derived controls, including mswinsck.ocx?

I'm about to try sticking a 'busy' flag in the Receive event, so that
nothing else can happen (e.g. lstBox.Clear, Form_Resize etc) while the
flag is set.

MM



Sun, 30 Oct 2011 01:26:47 GMT  
 DsSocket never happy when interrupted in Receive event

Quote:
> I've noticed that DsSocket works fine PROVIDED it is NOT interrupted
> in any way while in its Receive event. For example, just a simple
> lstBox.Clear is enough to throw it completely. It just seems to lose
> sync with the newsserver.

> Anyone know (before I start experimenting) whether this is just a fact
> of life with Winsock-derived controls, including mswinsck.ocx?

> I'm about to try sticking a 'busy' flag in the Receive event, so that
> nothing else can happen (e.g. lstBox.Clear, Form_Resize etc) while the
> flag is set.

Normally, in MS Winsock control, DataArrival is not interrupted by other
events, including Timer events, unless you fire these events indirectly from
code in the DataArrival event, such as setting properties that would fire
other events.


Sun, 30 Oct 2011 02:29:25 GMT  
 DsSocket never happy when interrupted in Receive event


Quote:


>> I've noticed that DsSocket works fine PROVIDED it is NOT interrupted
>> in any way while in its Receive event. For example, just a simple
>> lstBox.Clear is enough to throw it completely. It just seems to lose
>> sync with the newsserver.

>> Anyone know (before I start experimenting) whether this is just a fact
>> of life with Winsock-derived controls, including mswinsck.ocx?

>> I'm about to try sticking a 'busy' flag in the Receive event, so that
>> nothing else can happen (e.g. lstBox.Clear, Form_Resize etc) while the
>> flag is set.

>Normally, in MS Winsock control, DataArrival is not interrupted by other
>events, including Timer events, unless you fire these events indirectly from
>code in the DataArrival event, such as setting properties that would fire
>other events.

However, I have just read this:
http://support.microsoft.com/default.aspx?scid=kb;en-us;178078

which suggests that the above behaviour doesn't occur in the compiled
.exe. It is, in fact, in the design environment where I experienced
the "unhappiness" problem. Elsewhere I read that an alternative is not
to use MsgBox in the design env but use the MessageBox API instead.

MM



Sun, 30 Oct 2011 16:38:56 GMT  
 DsSocket never happy when interrupted in Receive event

Quote:


>>Normally, in MS Winsock control, DataArrival is not interrupted by other
>>events, including Timer events, unless you fire these events indirectly
>>from
>>code in the DataArrival event, such as setting properties that would fire
>>other events.

> However, I have just read this:
> http://support.microsoft.com/default.aspx?scid=kb;en-us;178078

> which suggests that the above behaviour doesn't occur in the compiled
> .exe. It is, in fact, in the design environment where I experienced
> the "unhappiness" problem. Elsewhere I read that an alternative is not
> to use MsgBox in the design env but use the MessageBox API instead.

I tested MsgBox with 2 Timers, and in the EXE, it blocks the same Timer, but
not another Timer. The same thing happen with modal forms. I think this was
introduced in VB6+SP3. Normally I don't use any code in DataArrival that
blocks execution, including all the routines called by DataArrival. If I
want to call code that blocks, I defer the processing to another routine
using a Timer, or PostMessage. Below is PostMessage method. To try it, add a
hidden Command button with Name btnHidden, then paste the following code:

Private Const WM_CHAR = &H102
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" ( _
    ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
    ByVal lParam As Long) As Long

Private Enum enumProcessLaterMode
    enumModeShowMsgBox
    enumModeShowForm1
End Enum

Dim m_ProcessLaterMode As enumProcessLaterMode
Dim m_ProcessLaterData As String

Private Sub ProcessLater(ByVal mode As enumProcessLaterMode, Optional ByRef
data As String)
    m_ProcessLaterMode = mode
    m_ProcessLaterData = data
    PostMessage btnHidden.hwnd, WM_CHAR, mode, ByVal 0&
End Sub

Private Sub btnHidden_KeyPress(KeyAscii As Integer)
    Debug.Print "btnHidden_KeyPress: KeyAscii = " & KeyAscii
    ' Process requests
    Select Case m_ProcessLaterMode
        Case enumModeShowMsgBox:
            MsgBox m_ProcessLaterData
        Case enumModeShowForm1:
            Form1.Show vbModal, Me
    End Select
End Sub

The above code defers execution to KeyPress event so we don't have to
subclass the form. It doesn't handle more than one request. If you want to
handle multiple requests, then put both "m_..." variables above in a UDF,
perhaps in an array in a class and use it as a collection.

Also, instead of using MsgBox for debugging EXE, use OutputDebugString().
The output can be viewed by this free software:

DebugView:
http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx

Declaration:

Public Declare Sub OutputDebugString Lib "kernel32" Alias _
    "OutputDebugStringA" (ByVal lpOutputString As String)

Usage:

OutputDebugString "ABC"

Wrapper sub:

Public Sub DebugPrint(ByRef s As String)
    OutputDebugString s
End Sub



Sun, 30 Oct 2011 20:05:34 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. How to Receive Events from Event View on NT

2. Interrupt Events to Allow Paint Form

3. Need a TIME Event or Interrupt in VB5 or VC++5

4. Interrupting Events?

5. Interrupt an event

6. How do I get the size of a file using Interrupt or Interrupt

7. Send/Receive event

8. receive mail trigger event

9. Help: How to receive .Net Dll Event in VB6

10. raising and receiving events

11. Receiving a single event on multiple forms?

12. Receive events from Windows?

 

 
Powered by phpBB® Forum Software