It's late so this may be a "Doh!" incident but...
I've got one thread which for instance I'll call the main thread and another thread which I'll call a worker thread.
The main thread is doing this:
Do
LoopGDK()
returnEvent = GetCoreEvent("test_Button")
If returnEvent.Catagory <> dgdkEvent.EventCatagory.Empty Then
Return False
End If
Thread.Sleep(100)
Loop
The worker thread is running like this:
Private Sub EventHandler()
Do
ProcessEvents()
UpdateComponents()
Thread.Sleep(100)
Loop
End Sub
Private Sub UpdateComponents()
For Each dictEntry As DictionaryEntry In _components
Dim acomponent As dgdkComponent = CType(dictEntry.Value, dgdkComponent)
Dim resultEvent As dgdkEvent = aComponent.MouseAction(MouseX, MouseY, MouseButton)
If resultEvent.Catagory <> dgdkEvent.EventCatagory.Empty Then
resultEvent.ToID = STR_CORE
SendEvent(resultEvent, _ProcessID)
End If
Next
End Sub
There is only one component in the _components collection which is this:
Public Class dgdkButton
Inherits dgdkComponent
Private _buttonUpImageID As String
Private _buttonDownImageID As String
Private _buttonPressed As Boolean
Private _inZone As Boolean
Public Sub New(ByVal buttonID As String, ByVal buttonX As Integer, ByVal buttonY As Integer, ByVal buttonUpImageID As String, ByVal buttonDownImageID As String, ByVal showNow As Boolean)
ID = buttonID
_buttonUpImageID = buttonUpImageID
_buttonDownImageID = buttonDownImageID
_buttonPressed = False
ImageLoad(buttonDownImageID)
ImageLoad(buttonUpImageID)
Zone = ImageGetZone(buttonX, buttonY, buttonUpImageID)
If showNow = True Then
RefreshDisplay()
End If
End Sub
Public Sub New(ByVal buttonID As String, ByVal buttonX As Integer, ByVal buttonY As Integer, ByVal buttonUpImageID As String, ByVal buttonDownImageID As String)
Me.New(buttonID, buttonX, buttonY, buttonUpImageID, buttonDownImageID, False)
End Sub
Public Overrides Sub RefreshDisplay()
If _buttonPressed = True Then
ImagePaste(Zone.X, Zone.Y, ButtonDownImageID)
Else
ImagePaste(Zone.X, Zone.Y, ButtonUpImageID)
End If
If _inZone = True Then
HilightZone()
End If
Sync()
End Sub
Public Overrides Function MouseAction(ByVal mouseX As Integer, ByVal mouseY As Integer, ByVal mouseButton As Integer) As dgdkEvent
Dim anEvent As New dgdkEvent
anEvent.EventSource = ID
If Zone.IsInZone(mouseX, mouseY) = True Then
If _inZone = False Then
_inZone = True
RefreshDisplay()
End If
Else
If _inZone = True Then
_inZone = False
RefreshDisplay()
End If
End If
Return anEvent
End Function
Public Property ButtonUpImageID() As String
Get
Return _buttonUpImageID
End Get
Set(ByVal value As String)
_buttonUpImageID = value
End Set
End Property
Public Property ButtonDownImageID() As String
Get
Return _buttonDownImageID
End Get
Set(ByVal value As String)
_buttonUpImageID = value
End Set
End Property
Private Sub HilightZone()
Box(Zone, False)
End Sub
End Class
The main thread seems to be running round its loop with no issues.
The worker thread gets to this line in the button object and runs the ImagePaste sub:
ImagePaste(Zone.X, Zone.Y, ButtonUpImageID)
The ImagePaste code is:
Public Function ImagePaste(ByVal x As Integer, ByVal y As Integer, ByVal ID As String) As Boolean
Dim image As tyranntImage
If mediaStore.ContainsKey(ID) Then
image = CType(mediaStore(ID), tyranntImage)
If ImageExists(image.ImageID) = True Then
SyncLock oDBImage
oDBImage.PasteImage(image.ImageID, x, y)
End SyncLock
Return True
Else
Return False
End If
Else
FatalError("PasteImage", "Image " & ID & " Doesn't exist")
Return False
End If
End Function
The thread seems to stop at:
oDBImage.PasteImage(image.ImageID, x, y)
and will not continue.
But strangely enough, If I change the main thread by adding a Sync()
Public Sub Sync()
SyncLock oDBCore
oDBCore.Sync()
End SyncLock
End Sub
to:
Do
LoopGDK()
returnEvent = GetCoreEvent("test_Button")
If returnEvent.Catagory <> dgdkEvent.EventCatagory.Empty Then
Return False
End If
Sync()
Thread.Sleep(100)
Loop
The paste unlocks during the sync.
Anyone have any ideas about this?
Cheers,
Jas
----
"What is this talk of 'release'? Klingons do not'release' software. It escapes leaving a bloody trail of developers and quality assurance people in its wake!"