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

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
0
dufus
11/25/2009 7:53:43 PM
dotnet.languages.vb 830 articles. 0 followers. Follow

6 Replies
1064 Views

Similar Articles

[PageSpeed] 33

In article
<7099a461-bf95-44da-b5d0-b2374da3f5c3@z35g2000prh.googlegroups.com>,
<dufus@connectedvision.com> wrote:

> 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).

-- 
J.B. Moreno
0
J
11/25/2009 9:52:05 PM
On Nov 25, 1:52=A0pm, "J.B. Moreno" <pl...@newsreaders.com> wrote:
> In article
> <7099a461-bf95-44da-b5d0-b2374da3f...@z35g2000prh.googlegroups.com>,
>
>
>
>
>
> <du...@connectedvision.com> wrote:
> > I have something I'm writing as a windows form right now but it will
> > eventually be a Windows Service. =A0For a test, I have a submit button
> > and it's action is to call something that dials out on a usb phone
> > device. =A0While 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. =A0The device I call has a bunch of handlers that
> > handle the keys being entered, etc. =A0I 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... =A0Thanks very
> > much. =A0 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 =3D 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. =A0I 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).
>
> --
> J.B. Moreno- Hide quoted text -
>
> - Show quoted text -

Thanks for the pointer.  The backgroundworker class is exactly the
hint I was looking for....
-1
Stupid488
11/25/2009 10:02:15 PM
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



0
Stupid488
11/26/2009 12:04:59 AM
Stupid488 <dufus@connectedvision.com> wrote:

> 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
0
J
11/26/2009 12:21:32 AM
J.B. Moreno <planB@newsreaders.com> wrote:

> Stupid488 <dufus@connectedvision.com> wrote:
> 
> > 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
0
J
11/26/2009 12:30:42 AM
On Nov 25, 4:30=A0pm, "J.B. Moreno" <pl...@newsreaders.com> wrote:
> J.B. Moreno <pl...@newsreaders.com> wrote:
> > Stupid488 <du...@connectedvision.com> wrote:
>
> > > Actually, I still have a problem. =A0I created a background worker
> > > process and moved the line that calls the dialer to the DoWork
> > > event... =A0The problem is that the RunWorkerCompleted event happens
> > > right after it runs the dialer...
>
> > > The dialer is run like this: Dim xError As CWay2callDriver.Errors =3D
> > > 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. =A0If 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- Hide quoted text -
>
> - Show quoted text -

Good point.  I will go this route....
0
Stupid488
11/26/2009 12:41:28 AM
Reply:

Similar Artilces:

Window Live Mail Automatically Files Downloaded Messages
I am wondering if someone can tell me why WLM is downloading new messages in a folder sometimes and not going into the Inbox, or Unread messages? An example is that if someone sends me a message with the subject ABC.... it will go into my ABC folder, not the inbox. The only whay I see it is if I do a search. When the search finds it, it shows as unread? Any help would be appreciated -- David Chisnell Did you install WLMail on a computer that had that message rule in an earlier email program? -- Ron Sommer MS MVP- Windows Live Mail "David Chisnell" <Dav...

PDF: How to install Service Pack 1 for SBS 2003
Hi all, Because of the server move I took the PDF for SP1 offline because it was causing to much traffic on the old server. It is again available at: How to install Service Pack 1 for SBS 2003: http://www.smallbizserver.net/Default.aspx?tabid=266&articleType=ArticleView&articleId=68 Bye -- Mari�tte Knap Microsoft SBS-MVP One of the Magical M&M's www.smallbizserver.net Take part in SBS forum: http://www.smallbizserver.net/Default.aspx?tabid=53 ...

Problem with blocking of main thread with other thread
I have a problem with blocking of main thread: My application contains an interpreter and I need to write a debugger for it. The mainframe creates a thread that is interpreting instructions. When I need to break execution of instruction thread, I use WaitForSingleObject(m_WaitEventHandle, INFINITE); in the interpreter thread. Everything works fine until the window is opened from the interpreter. Then the mainframe freezes. When I break execution in VC the call stack for interpreter thread shows: � NTDLL! � KERNEL32! � CDebugManager::CheckBreakpoints() � CInterpreterThread::Run() � _Afx...

IE 8 will not allow Adobe Reader download
Recently I updated to IE 8 on a winXP Service pack 3 machine. I believe the machine was infected with something at the time. I was using Avast and AVG Antivirus that were not finding anything though. The machine was very slow though so I purchased Registry/Idenity Patrol and ran that several times. It would find less things each time but got down to six items it would not remove. The computer runs much faster now but is unstable. When I try to download Adobe reader or Flash it immediatly locks IE and I get a message about maliious add ons. Also, I uninstalled all other Virus prog...

Where is my thread?
I posted a question about "Search for a value in multi-dimensionla array" an hour ago; where did that go? On 5/17/2010 17:38, Rick wrote: > I posted a question about "Search for a value in multi-dimensionla array" an > hour ago; where did that go? If you mean the one beginning with "Seach", posted almost half an hour before this one, it is there. :) On 5/17/2010 11:51 AM, Jackie wrote: > On 5/17/2010 17:38, Rick wrote: >> I posted a question about "Search for a value in multi-dimensionla >> array" an >> hour ag...

Repost: Will not save until ESC or Undo
Hi All, (Sorry for the repost, but it is urgent) I created an application starting with the Time and Billing template. Originally I had the data going into SharePoint but SP could not handle the data (local rules). Now the back-end is in SQL Server 2005, but I digress. The problem seems to be in the forms. When I create a new record in the Project List form (Split form with datasheet showing) i must move to the next field and hit escape or undo before the record saves. It is also now doing this in my details form (Single Form). I went through the steps for fixing corruptio...

Parallel port under Windows 7
Did somebody try writing values to parallel port under Windows 7? So far I am unable to do it. Stuff that worked on XP doesn't under Win7. CreateFile("LPT3"...) succeeds but all subsequent commands (GetCommState, WriteFile) fail. I stopped spooling and followed recommendations from http://support.microsoft.com/kb/823179/en-us. Didn't help. InpOut32.dll does not work on 64 bit version (which is expected), but even 32 bit version works on some computers and doesn't on the others. Specifically, it works on the PC with LPT port on a separate I/O card (appea...

Excel will not open #3
Windows 98SE, latest updates Pentuim II 320 MB RAM Office 2000, latest updates Spyware Blaster Version 3.2, free, updated daily Spybot Search & Destroy version 1.3, free, updated daily Ad-Aware version 6.0 Standard, free, updated daily Kasperski AV version 4.5.0.94, paid, automatically updated daily Excel will not open. Causes fatal exception OE 0167:BFF9DFFF I have been running MS Office 2000, expecially excel, on this machine for three years with no problems I repaired office. I removed Office and re-installed office. I have searched and searched. Found words and sentences, but ...

cannot get BCM to work on Office Enterprise 2007 and Windows 7
I have Windows 7 and Office enterprise 2007 and tried to install BCM 2007 and got it installed then opened Outlook and said it could not setup database. Is BCM 2007 compatible with Enterprise and Windows 7. Is there a work around? ...

Active Directory , Windows 2003 SBS to Windows 2008 SBS
Hello! I've got a little issue here. I work for a company and we are getting a new Intelserver. Now the problem is we've got an 32bit windows 2003 small business server with an Active Directory (and sql). And we are getting a Windows 2008 Small business server 64bit. Is there any possible way to ''Transfer'' ''Move'' or ''Copy'' the Active Directory to his new server without changing, removing or adding any data. I really need to be sure that nothing goes wrong cause 25 people are working on it everyday (Ofcourse i have a...

Diaglog/Threading Data Exchange Question
Greetings, I have learned a lot from all of you, and I hope to over come my latest road block. I have a smal IRC Chat client I am making. I have a Dialog Box with Control and I use a worker thread for connecting to IRC - That Thread will update controls on the Dialog by sending PostMessages. Now my problem is in the ListBox Control that I have extended to do popup menu with various commands. I need to be able to read that controls methods from within the Thread. so I need to do this from within my IRC Socket thread: (code not exact - pseudo code) CListBoxEx myUsers; //Defined in my ...

How to call web method of DynamicsGP Web Services using apache axis
Hi Everyone, I am battling an issue and I figured one of you guys on this forum may be able to help. I have a developed an application in java to access Microsoft Dynamics 10.0 through Web Services. I post a SOAP request to DynamicsGPWebService.asmx web services and get a SOAP response that is handled in my java program using simple XML parsing. I want to achieve the same using objects in Apache AXIS. The first issue is that how can I list out all the webmethods available in the web services. The next issue is once I get a webmethod, how can I list out all the available fields of that webm...

Need Help with Busy Dialog Thread
my application would perform a task. I want to stop the user from using the application's GUI untill the the BG task is finished. At first using Modal Dlg did not do the trick as every one now (apart from me) the the CDialog::DoModal() function has to return some how. So, I made a bit of research on the net and found a trick to display the Dialog using CWinThread derived class without stoping the main app window for executing the background task as follows: (1) In your header file define a CWinThread-derived class... class CDialogThread : public CWinThread { DECLARE_DYNCREATE(CDial...

My outlook will not do spell check.
I have not been able to use the in program speel check for outlook express, since I loaded XP. What do I need to do to make it work? You will need a MS program like word. There is no Spell check in Outlook Express "Philip Wheeler" <pwheeler@surewest.net> wrote in message news:00d401c3552e$342ac2a0$a401280a@phx.gbl... > I have not been able to use the in program speel check > for outlook express, since I loaded XP. What do I need > to do to make it work? ...

Windows XP .Net Framework Failure
I've been having problems with trynig to install the .NET Framework 1.1 and 3.5 updates. Everytime I try to install them through microsoft's update it keeps saying failure, I have even manually downloaded them and it still gives me the same error. I looked at other problems and tried to do the same thing people tried to help them with. Can someone please help me? Thanks. -- gotenbw ------------------------------------------------------------------------ gotenbw's Profile: http://forums.techarena.in/members/224621.htm View this thread: http://forums.techarena...

Outlook will not start #2
I had aa copy of MS Office Professional 2000 on my computer, which came with the computer, so no roigianl disk. I got Office XP small Business Ed. I installed the new software with no problems, but when I try to start Outlook, I get the following message: "UNABLE TO OPEN DEFAULT E-MAIL FOLDERS THE .DLL FILE FOR THE INFORMATION SERVICE COULD NOT BE FOUND. MAPI WAS UNABLE TO LAD THE INFORMATION SERVICE PSTPRX.DLL. BE SURE THE SERVICE IS CORRECTLY INSTALLED AND CONFIGURED." Because of this problem, Outlook is completely useless. I have searched the dll sites for the pstpr...

Simple Thread
I have created a thread in my MFC Dialog based application, in the thread function i want to have access to a user interface control that is attached to the main dialog. How can I do it? Regards, Mystique Mystique wrote: > I have created a thread in my MFC Dialog based application, in the thread > function i want to have access to a user interface control that is attached > to the main dialog. > How can I do it? > > Regards, > Mystique > > Indirectly, by posting a message to the main thread asking it to update the control. http://www.mvps.org/vcfaq/mfc/12.ht...

Maximized SDI window
Hi, I have: m_pMainWnd->ShowWindow(SW_MAXIMIZE); instead of: m_pMainWnd->ShowWindow(SW_NORMAL); because with SW_NORMAL the window isn't maximized when the app starts. ;-( When SW_MAXIMIZE is used, size of window is changing while click New or Open. How to avoid this? This is a SDI application with view based on CFormView. Thanks for help. -- Deli You might want to try this library. I use it and it even resizes the controls in the formview. It's handy. Tom http://www.codeproject.com/property/resizableproperties.asp?df=100&forumid=913&exp=0&select=5063...

I need to know if something happens once each calendar month
Our case managers need to see clients once each caledar month. Any time within a calendar month. How can I report if a task has been each calendar month? Thanks Kelvin On Thu, 3 May 2007 16:12:17 -0500, "Kelvin Beaton" <kelvin at mccsa dot com> wrote: >Our case managers need to see clients once each caledar month. >Any time within a calendar month. > >How can I report if a task has been each calendar month? > >Thanks > >Kelvin > Each calendar month over... what span? How are your Tasks stored, and how are task accomplishments stored? Basica...

IE8 32bit Windows 7 Home Premium crashes immediately on opening
I've seen this problem all over the internet starting last summer, but none of the threads seem to have a solution. IE8 32-bit running on Windows 7 crashes immediately upon opening. It does not offer to send the log to microsoft after checking for a solution. The only option is close program. If I "Run as Administrator" I can get the 64 bit version working, but that turns off protected mode and is undesirable. This just started a couple days ago, and NOTHING I've found or tried in a ream of threads (that happen in Vista also) solves the problem. A few th...

Inserting something at the begining of evrey cell
How can I insert soemthing at the begining of evrey cell in a column? i.e. Product Name1 Product Name2 Product Name3 Product Name4 Product Name5 into Something Product Name1 Something Product Name2 Something Product Name3 Something Product Name4 Something Product Name5 As always, TIA, Jav ----------------------------------------------- ~~ Message posted from http://www.ExcelTip.com ~~View and post usenet messages directly from http://www.ExcelForum.com try this Sub addtext() For Each c In range("i4:i24") If Len(c) > 0 Then c.Value = "add " & c Next End Sub ...

Will I Be Able to Xfr my Payee List
I am looking at moving from Quicken and Quicken BillPay to Money and want to know if Money will import my existing list of Payees (including online payees)? A related question - In looking through the various versions of Money I don't see any online payment option. Does Money have a way to pay bills online (including recurring payments) like Quicken BillPay? "Wayne Wengert" <wayneSKIPSPAM@wengert.org> wrote in message news:OCpgXhnVHHA.4188@TK2MSFTNGP06.phx.gbl... >I am looking at moving from Quicken and Quicken BillPay to Money and want >to know if Money w...

attaching child ClistCtrl window to resizable parent Dialog
I'm using Visual C++ 7.0 and MFC With the Wizard, I created a Dialog Window [which I made resizable]. I've place two ClistCtrls side by side on the top of the dialog. I'd like to attach the RHS of the rightmost ctrl to the parent dialog so that when I resize the dialog, the listctrl expands. Note that I don't explicitly create the listctrls - this ia all behind the scene. I only send an initial message to each: m_ConfCtrlList.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE,0, LVS_EX_FULLROWSELECT|LVS_REPORT|LVS_EX_GRIDLINES ); Thanks, Ihor VC++ doesn't not...

Windows Mail
All of a sudden I am having difficulty receiving/sending emails. I have webmail.carolina.rr.com which are then forwarded to my laptop via windows mail. I started receiving duplicate emails last week, same email up to 20 times. I verified with the server that the dups are not on their end. coincedentally, my internet connection is pathetically slow. Can this issue affect my internet speed? Anyone have any advice? I have already verified that I am set up correctly. Yesterday I ran CCcleaner, superspy ware, and malwarebytes and came up clean. Not sure what is happening. MI...

Killing thread from outside thread in MFC App
Hi, Thanks to all those who offered advise on my last query. I successfully used the worker thread method to give control back to the dialog box whilst background processing was being carried out. The issue I have now is closing that thread externally. The method I've used to create the thread uses a volatile boolean variable. Whilever it is set to TRUE, the thread remains alive. However, when I set the variable to FALSE from the calling process (user wants to end processing), it has no effect. The thread continues to run. I thought that declaring the variable as 'volatile'...