Running Events at the same time

ok... I have an array of winsock controlls. the winsock controlls are called wsktoclient. when a wsktoclient data arival event is risen(index one we'll say) it takes a long to time to exicute... it could take hours(it sends files in this event). when another one is risen(index two) the program exicutes the index two event and does not work on index one untill it is finished with the index two event. how do i keep both events exicuting simultaniously?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If you are using NT or Win9x you could put your events in seperate threads. Or you could make a single use out-of-process ActiveX exe that executes the event.

Hope this helps,
hessAuthor Commented:
That is what i wnat to know how to do... i should have stated it better. how do i put hte events in seperate threads
hessAuthor Commented:
or where can i learn to use more threads... that is currently above me
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Here is a sample from Bruce McKinneys book. Hope it helps to get you started

In a .bas module:

Option Explicit

Declare Function CreateThread Lib "KERNEL32" ( _
    ByRef lpThreadAttributes As Any, _
    ByVal dwStackSize As Long, _
    ByVal lpStartAddress As Long, _
    ByRef lpParameter As Any, _
    ByVal dwCreationFlags As Long, _
    ByRef lpThreadId As Long) As Long

Declare Sub ExitThread Lib "KERNEL32" ( _
    ByVal dwExitCode As Long)
Declare Sub CloseHandle Lib "KERNEL32" ( _
    ByVal h As Long)
Declare Function GetExitCodeThread Lib "KERNEL32" ( _
    ByVal hThread As Long, _
    ByRef lpExitCode As Long) As Long

Declare Sub Sleep Lib "KERNEL32" (ByVal dwMilliseconds As Long)
Declare Function GetTickCount Lib "KERNEL32" () As Long

Const STILL_ACTIVE = 259
Const pNull As Long = 0

Private fRunning  As Boolean
Private cCalc     As Long
Private cAPI      As Long
Private datBasic  As Date
Private hThread   As Long
Private idThread  As Long

Sub StartThread(ByVal i As Long)
    ' Signal ThreadProc that thread is starting
    fRunning = True
    ' Create new thread
    hThread = CreateThread(ByVal pNull, 0, AddressOf ThreadProc, _
                           ByVal i, 0, idThread)
    If hThread = 0 Then MsgBox "Can't start thread"
End Sub

Function StopThread() As Long
    ' Signal thread to stop
    ' Next statement signals ThreadProc to ExitThread
    fRunning = False
    ' Make sure thread is dead before returning exit code
        Call GetExitCodeThread(hThread, StopThread)
    Loop While StopThread = STILL_ACTIVE
    CloseHandle hThread
    hThread = 0
End Function

Function ThreadRunning() As Boolean
    ThreadRunning = fRunning
End Function

Function CalcCount() As Long
    CalcCount = cCalc
End Function

Function APICount() As Long
    APICount = cAPI
End Function

Function BasicTime() As Date
    BasicTime = datBasic
End Function

Sub ThreadProc(ByVal i As Long)
    ' Use parameter
    cCalc = i
    Do While fRunning
        ' Calculate something
        cCalc = cCalc + 1
        ' Use an API call
        cAPI = GetTickCount
        ' Use a Basic function
        datBasic = Now
        ' Switch immediately to another thread
        Sleep 1
    ' Return a value
    ExitThread cCalc
End Sub
your problem is very well described in this qoutation from MSDN :
Caution:   Any time you temporarily yield the processor within an event procedure, make sure theprocedure is not executed again from a different part of your code before the first call returns; this could cause unpredictable results.

now, to your question : "how do i keep both events exicuting simultaniously?" -
there is only one answer - *THREADS* .

i can assure you that no trick will make your current concept work unless you'll have only 1-2 clients....

i recommend you to create ActiveX EXE object that will be defined as 'Thread Per Object', and that will contain that winsock control.
you main app cam instanciate as many objects like that as you want (depending on machine\server resources), and each will run in his own thread. the Operating system will take care to execute the events simulantly.

if you don't know how to create ActiveX EXE - post a question.....good luck


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hessAuthor Commented:
I have a max of 16 clients(it can be expanded) and i used timers to solve my problem. now i don't get traped in one event for a long time... things all work now. thankyou... i'll deal with threads later
if the data traffic is heavy - your way won't do the job even 80%. data will be lost.
Good Luck anyway.
hessAuthor Commented:
why... i can send out a max of 15 files... and the timers turn themselves on and off..15 at a time is the max that i need to send
hessAuthor Commented:
why... i can send out a max of 15 files... and the timers turn themselves on and off..15 at a time is the max that i need to send
that's not multithreading. that's ONE thread doing all that...
you may get away with it in this one - but it ain't a serius programing.
when you'll come to REAL stuff this won't be enough.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.