Cracked it. :coffee2:
The 'Control Set Text' in MainThread was also causing a problem.
So, I used PostMessage there as well.
If we change 'Post' to 'Send' in MainThread then we get NewThread coming in after MainThread.
If we change 'Post' to 'Send' in NewThread then we get a pedestrian NewThread.
However, both functions now spit out iCount& so fast that I have had to restrict the reporting to iCount& increments of 50 for my machine. I'd be interested in knowing if that is OK for other machines.
So, no 'Dialog DoEvents 0' now and we are using a primary thread plus secondary thread as Gary's original post.
I've done a bit of tidying up as well and if I may coin a phrase from you know who "Look, Ma, no globals".
The 'Control Set Text' in MainThread was also causing a problem.
So, I used PostMessage there as well.
If we change 'Post' to 'Send' in MainThread then we get NewThread coming in after MainThread.
If we change 'Post' to 'Send' in NewThread then we get a pedestrian NewThread.
However, both functions now spit out iCount& so fast that I have had to restrict the reporting to iCount& increments of 50 for my machine. I'd be interested in knowing if that is OK for other machines.
So, no 'Dialog DoEvents 0' now and we are using a primary thread plus secondary thread as Gary's original post.
I've done a bit of tidying up as well and if I may coin a phrase from you know who "Look, Ma, no globals".

Code:
#Compile Exe #Dim All #Include "Win32API.inc" %Start = 100 %Main = 101 %Extra = 102 %Private = %WM_USER + 501 Function PBMain() As Long Local hDlg As Long Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg Control Add Button, hDlg, %Start,"Start Thread", 50,10,100,20 Control Add Label, hDlg, %Main,"<main thread count>", 50,40,100,20 Control Add Label, hDlg, %Extra,"<extra thread count>", 50,70,100,20 Dialog Show Modal hDlg Call DlgProc End Function CallBack Function DlgProc() As Long Local hThread As Long Dim Text( 0 To 1 ) As String Text(0) = "Main" Text(1) = "Thread" Select Case As Long CB.Msg Case %Private Control Set Text CB.Hndl, %Main + CB.lParam, Text(CB.lParam) + Str$(CB.wParam) Case %WM_COMMAND Select Case As Long CB.Ctl Case %Start If CB.CtlMsg = %BN_CLICKED Then Thread Create NewThread(CB.Hndl) To hThread Thread Close hThread To hThread MainThread(CB.Hndl) End If End Select ' WM_COMMAND End Select ' CB.Msg End Function Function MainThread (ByVal hWnd As Long) As Long Local iCount& Do Incr iCount& If iCount& Mod 50 = 0 Then PostMessage hWnd, %Private, iCount&, 0 Loop Until iCount& > 200000 End Function Thread Function NewThread (ByVal hWnd As Long) As Long Local iCount& Do Incr iCount& If iCount& Mod 50 = 0 Then PostMessage hWnd, %Private, iCount&, 1 Loop Until iCount& > 200000 End Function
Comment