08-11-2007, 01:32 PM
Spodi Wrote:You could easily just do it once every minute or two. It doesn't have to be often.
I have no idea how threading would help at all, unless you are using the thread in a completely stupid manner like spawning a new thread just to send the packet after an elapsed amount of time.
threads are not bad. in vb.net, you would do something like
Code:
dim T as Threading.Thread
sub form1_Load(byval sender as object, byval e as system.eventArgs) handles form1.load
T = new threading.thread(addressof CheckClientsSpeed)
T.Priority = Priority.low
t.Start
end sub
Code:
sub CheckClientsSpeed()
while true
threading.thread.currentThread.sleep(40000) ' 40 seconds
'um using my engine as an example
Dim myEnumerator As IDictionaryEnumerator = _USERS.GetEnumerator()
While myEnumerator.MoveNext()
If UserOnline(DirectCast(myEnumerator.Value, clsPlayer)) Then
SendTo(DirectCast(myEnumerator.Value, clsPlayer), PTD.TimeRequest)
End If
End While
end while
end sub
or if you were more oop
Code:
sub CheckClientsSpeed()
while true
threading.thread.currentThread.sleep(40000) ' 40 seconds
'um using my engine as an example
SendToAll(PTD.TimeRequest)
end while
end sub
threads reduce the strain on a program and can speed things up alot, but you run into lots of problems accessing forms with other threads and stuff.