How to thread something in what will become a Windows Service....

  • Thread starter Thread starter dufus
  • Start date Start date
D

dufus

I have something I'm writing as a windows form right now but it will
eventually be a Windows Service. For a test, I have a submit button
and it's action is to call something that dials out on a usb phone
device. While that device is dialing and waiting for DTMF input from
the call recipient, I need to pause the program and wait for the
callee to hang up. The device I call has a bunch of handlers that
handle the keys being entered, etc. I need to have these handlers
able to listen for events while the button click sub is waiting but be
able to continue when a hangup event occurs. I'm not asking for
someone to write code for me but just looking for some of the words I
can search for on the internet or some pointers... Thanks very
much. Chris

I've attached a bit of the code...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

AddHandler CWay2callDriver.OnLineCurrentDrop, AddressOf OnLineDrop

Dim xError As CWay2callDriver.Errors = DirectCast(w2cDrv.Device.[Call]
("w" & strNumber, True, True), CWay2callDriver.Errors) 'So this is
where it calls out....

'I need to sort of pause here and not actually end the sub. I tried
adding a do/while but it is in such a tight loop that the events never
fire when things happen on the dialer.

End Sub

Private Sub OnLineDrop(ByVal deviceID As UShort)
MyHangUpCall = 0
w2cDrv.Device.HangUp(False)
w2cDrv.Device.Close(0)
'close the device
' handle errors ...
w2cDrv.ShutdownDriver(0)
boolCallFinished = True
End Sub
 
I have something I'm writing as a windows form right now but it will
eventually be a Windows Service. For a test, I have a submit button
and it's action is to call something that dials out on a usb phone
device. While that device is dialing and waiting for DTMF input from
the call recipient, I need to pause the program and wait for the
callee to hang up. The device I call has a bunch of handlers that
handle the keys being entered, etc. I need to have these handlers
able to listen for events while the button click sub is waiting but be
able to continue when a hangup event occurs. I'm not asking for
someone to write code for me but just looking for some of the words I
can search for on the internet or some pointers... Thanks very
much. Chris

I've attached a bit of the code...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

AddHandler CWay2callDriver.OnLineCurrentDrop, AddressOf OnLineDrop

Dim xError As CWay2callDriver.Errors = DirectCast(w2cDrv.Device.[Call]
("w" & strNumber, True, True), CWay2callDriver.Errors) 'So this is
where it calls out....

'I need to sort of pause here and not actually end the sub. I tried
adding a do/while but it is in such a tight loop that the events never
fire when things happen on the dialer.

You can't just pause, what you need to do is start a thread that does
your call and then returns whatever result it returns when finished (if
using BackgroundWorker that would be the whatever function you have to
handle the RunWorkerCompleted event).
 
I have something I'm writing as a windows form right now but it will
eventually be a Windows Service.  For a test, I have a submit button
and it's action is to call something that dials out on a usb phone
device.  While that device is dialing and waiting for DTMF input from
the call recipient, I need to pause the program and wait for the
callee to hang up.  The device I call has a bunch of handlers that
handle the keys being entered, etc.  I need to have these handlers
able to listen for events while the button click sub is waiting but be
able to continue when a hangup event occurs. I'm not asking for
someone to write code for me but just looking for some of the words I
can search for on the internet or some pointers...  Thanks very
much.   Chris
I've attached a bit of the code...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
AddHandler CWay2callDriver.OnLineCurrentDrop, AddressOf OnLineDrop
Dim xError As CWay2callDriver.Errors = DirectCast(w2cDrv.Device.[Call]
("w" & strNumber, True, True), CWay2callDriver.Errors) 'So this is
where it calls out....
'I need to sort of pause here and not actually end the sub.  I tried
adding a do/while but it is in such a tight loop that the events never
fire when things happen on the dialer.

You can't just pause, what you need to do is start a thread that does
your call and then returns whatever result it returns when finished (if
using BackgroundWorker that would be the whatever function you have to
handle the RunWorkerCompleted event).

Thanks for the pointer. The backgroundworker class is exactly the
hint I was looking for....
 
Actually, I still have a problem. I created a background worker
process and moved the line that calls the dialer to the DoWork
event... The problem is that the RunWorkerCompleted event happens
right after it runs the dialer...

The dialer is run like this: Dim xError As CWay2callDriver.Errors =
DirectCast(w2cDrv.Device.[Call] ("w" & strNumber, True, True),
CWay2callDriver.Errors)

I still need to figure out how to not close the worker process before
the dialer's Onlinedrop event occurs...

hmmm
 
Stupid488 said:
Actually, I still have a problem. I created a background worker
process and moved the line that calls the dialer to the DoWork
event... The problem is that the RunWorkerCompleted event happens
right after it runs the dialer...

The dialer is run like this: Dim xError As CWay2callDriver.Errors =
DirectCast(w2cDrv.Device.[Call] ("w" & strNumber, True, True),
CWay2callDriver.Errors)

I still need to figure out how to not close the worker process before
the dialer's Onlinedrop event occurs...

In the worker thread you have a loop that checks a variable/property
that you set in the onlinedrop event.

You worker thread will probably call System.Threading.Thread.Sleep.
 
J.B. Moreno said:
Stupid488 said:
Actually, I still have a problem. I created a background worker
process and moved the line that calls the dialer to the DoWork
event... The problem is that the RunWorkerCompleted event happens
right after it runs the dialer...

The dialer is run like this: Dim xError As CWay2callDriver.Errors =
DirectCast(w2cDrv.Device.[Call] ("w" & strNumber, True, True),
CWay2callDriver.Errors)

I still need to figure out how to not close the worker process before
the dialer's Onlinedrop event occurs...

In the worker thread you have a loop that checks a variable/property
that you set in the onlinedrop event.

You worker thread will probably call System.Threading.Thread.Sleep.

On re-reading this, I"m not sure that you shouldn't have called Sleep
from the beginning -- I'm not clear on why you want to "pause" your
application. If you have an event that gets fired, and want to do
further processing after that event is fired, the thing to do is to
call for the processing inside the event handler.
 
J.B. Moreno said:
Actually, I still have a problem.  I created a background worker
process and moved the line that calls the dialer to the DoWork
event...  The problem is that the RunWorkerCompleted event happens
right after it runs the dialer...
The dialer is run like this: Dim xError As CWay2callDriver.Errors =
DirectCast(w2cDrv.Device.[Call] ("w" & strNumber, True, True),
CWay2callDriver.Errors)
I still need to figure out how to not close the worker process before
the dialer's Onlinedrop event occurs...
In the worker thread you have a loop that checks a variable/property
that you set in the onlinedrop event.
You worker thread will probably call System.Threading.Thread.Sleep.

On re-reading this, I"m not sure that you shouldn't have called Sleep
from the beginning -- I'm not clear on why you want to "pause" your
application.  If you have an event that gets fired, and want to do
further processing after that event is fired, the thing to do is to
call for the processing inside the event handler.

Good point. I will go this route....
 
Back
Top