M
Milosz - [playseven.com]
i have an app which has a WorkPrepare Class
the WorkPrepare class initializes a Worker class
in theWorkPrepare class there is a function initWork() started in a separate
thread (second thread), which starts Worker.doWork() in seperate threads in
an for each construct.
when the method Worker.doWork() is finished it fires an event to the
WorkPrepare class with its result.
My Problem is that only the last result reaches the WorkPrepare class. the
function that handles this event is only invoked with the result for the
last task.
I thought that the multiple threads are colliding in the event handling
function so only the last event is handled.
i tred an application.doevents after firiing the event and even if i fire
the event in an own function and make an mutex around it only the the last
event is recognized by the handling function..
what i am doing wrong ?
in simplified Code:
Class PrepareWork
Private th as thread
Private Worker as new Worker
Private Count as integer
sub new(cnt a integer)
me.Count = cnt
th = new thread(AdressOf initWork)
th.start
end sub
Sub initWork()
for i = 1 to Count
Worker.doWork(i)
next
end sub
'this method is only invoked from the last task, with i = Count
Private Sub getRespond(msg as string) Handles Worker.Respond
'get the respond Message
end sub
End Class
Class Worker
Friend Event Respond(msg as string)
Private m_i as integer
Public sub doWork(i as integer)
me.m_i = i
dim th as new thread(AdressOf mySpecialWork)
th.start
end sub
Private Sub mySpecialWork
'does something with me.m_i
.......
'
raiseevent Respond(i & " and what i have made with it")
end sub
End Class
Instead of firing the event from within the mySpecialWork metjod i have
tried
Private Sub mySpecialWork
'does something with me.m_i
.......
'
raiseevent Respond(i & " and what i have made with it")
end sub
Private Sub MakeResponse(msg a string)
me.mx.WaitOne() ' where mx is a Mutex initialized in the constructor
raiseevent Respond(msg)
application.doEvents
me.mx.Realese
End Sub
this had no effect
--
-> Milosz Weckowski
www.playseven.com
mailto:[email protected]
ICQ Number: 84867613
Get the enhanced Progressbar and a fine Colorpicker for the Compact Framwork
for free:
http://www.playseven.com/11620/p7_Controls.html
the WorkPrepare class initializes a Worker class
in theWorkPrepare class there is a function initWork() started in a separate
thread (second thread), which starts Worker.doWork() in seperate threads in
an for each construct.
when the method Worker.doWork() is finished it fires an event to the
WorkPrepare class with its result.
My Problem is that only the last result reaches the WorkPrepare class. the
function that handles this event is only invoked with the result for the
last task.
I thought that the multiple threads are colliding in the event handling
function so only the last event is handled.
i tred an application.doevents after firiing the event and even if i fire
the event in an own function and make an mutex around it only the the last
event is recognized by the handling function..
what i am doing wrong ?
in simplified Code:
Class PrepareWork
Private th as thread
Private Worker as new Worker
Private Count as integer
sub new(cnt a integer)
me.Count = cnt
th = new thread(AdressOf initWork)
th.start
end sub
Sub initWork()
for i = 1 to Count
Worker.doWork(i)
next
end sub
'this method is only invoked from the last task, with i = Count
Private Sub getRespond(msg as string) Handles Worker.Respond
'get the respond Message
end sub
End Class
Class Worker
Friend Event Respond(msg as string)
Private m_i as integer
Public sub doWork(i as integer)
me.m_i = i
dim th as new thread(AdressOf mySpecialWork)
th.start
end sub
Private Sub mySpecialWork
'does something with me.m_i
.......
'
raiseevent Respond(i & " and what i have made with it")
end sub
End Class
Instead of firing the event from within the mySpecialWork metjod i have
tried
Private Sub mySpecialWork
'does something with me.m_i
.......
'
raiseevent Respond(i & " and what i have made with it")
end sub
Private Sub MakeResponse(msg a string)
me.mx.WaitOne() ' where mx is a Mutex initialized in the constructor
raiseevent Respond(msg)
application.doEvents
me.mx.Realese
End Sub
this had no effect
--
-> Milosz Weckowski
www.playseven.com
mailto:[email protected]
ICQ Number: 84867613
Get the enhanced Progressbar and a fine Colorpicker for the Compact Framwork
for free:
http://www.playseven.com/11620/p7_Controls.html