Mouse move multithreading problem

  • Thread starter Thread starter Boni
  • Start date Start date
B

Boni

Dear all,
picturebox mouse move seems to start new thread each time it is called.
At least I see in debuger many threads.
---Non user code--
Picturebox.MouseMove

This seems to spoil my algorithm.
SyncLock Me
Do()
EndSyncloc

Don't fixes the problem.
Any advice would be greatly apreciated.
Best regards,
Boni
 
Boni said:
picturebox mouse move seems to start new thread each time it is called.
At least I see in debuger many threads.

I am not able to reproduce this behavior with .NET 1.1. Are you talking
about the control's 'MouseMove' event? Please post the relevant parts of
your source code.
 
Dear Herfried,
I use NET 1.1.

Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove

DoMove()

PictureBox1.Invalidate()

End Sub

Sub DoMove()

SyncLock m_Graph

Recalculate()

End SyncLock

End Sub



If some of internal assertions in Recalculate fails, I see in a debugger not
only one stack, but many of them.
 
I added to DoMove a flag to see, if I am right about the multithreading, and
assertion often fails.

Dim a As Boolean = False

Sub DoMove()

SyncLock m_Graph

If (a) Then

Debug.assert(false, "Multithreading!!!!")

End If





a = True

....



Recalculate()
a=false

End SyncLock
....

Boni said:
Dear Herfried,
I use NET 1.1.

Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove

DoMove()

PictureBox1.Invalidate()

End Sub

Sub DoMove()

SyncLock m_Graph

Recalculate()

End SyncLock

End Sub



If some of internal assertions in Recalculate fails, I see in a debugger
not only one stack, but many of them.
 
Each event returned by your control is NOT on a different thread. Each
windows application has a single UI thread which is processing events. Your
event handler routines are called from this single UI thread whenever an
event is received by the window. In the background Windows messages are
being processed and routed to each window handle. Your MouseMove event
handler will receive each event synchronously so there is no need for
SyncLock.

Boni said:
I added to DoMove a flag to see, if I am right about the multithreading, and
assertion often fails.

Dim a As Boolean = False

Sub DoMove()

SyncLock m_Graph

If (a) Then

Debug.assert(false, "Multithreading!!!!")

End If





a = True

....



Recalculate()
a=false

End SyncLock
....
 
Dear Sirs,
I do not understand,
If MouseMove started and is still running, but other MouseMove event happens
will it wait until first one is finished? How can I force this behavoir?
Thank you very much,
Boni
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top