Adam,
Thanks for your advice!
Yes, I have noticed in my app that the use of System.Threadin g.Timers is
very resource intensive especially when I have to constantly poll a scanner
to read in docs. I have implemented other approaches like the use of form
timers, etc but still the same problem. I am able to implement async timers
to my scanner routine but I am stuck in one simple area which I cannot
resolve without the use of threading timers. Consider the following code:
Sub AsyncCallBack()
Dim objAsyncDel As New AsyncPollScanDe legate(AddressO f RunThirdThread_ proc)
Dim objAsync As New AsyncCallback(A ddressOf MyCallBackThrea dPoolRoutine)
Dim objAR As IAsyncResult
objAR = objAsyncDel.Beg inInvoke(objAsy nc, Nothing)
Do Until objAR.IsComplet ed
'Do processing stuff
Loop
'objAsyncDel.En dInvoke(objAR)
End Sub
As you can see this will execute once and complete but how to I have the
program execute in an infinite loop without the use of timers?? The objAR
delegate will return IsCompleted and this routine will complete. For me to
implement a periodic polling technique is there another approach to above
without the use of threading timers?
Also, you mentioned ThreadPool threads. My app not only has to scan in
documents, but it has to process the documents by executing another program
to crop, despeckle, etc...and to produce thumbnail images of the scanned
images. The original programmer split up the processing into 4 main routines
(in VB6) which I implemented into 4 threadpool threads for my conversion to
VB.NET. Architecturally speaking, do you feel it is more efficient to split
these 4 threadpool threads into 4 async delegates instead??
Thanks!
Viet
"Adam Goossens" <ad**********@u sers.sourceforg e.net> wrote in message
news:#K******** ******@TK2MSFTN GP09.phx.gbl...
Hi Viet,
If your interface library to the scanner exposes an asynchronous means
of receiving data you should use it. It's more efficient in two senses:
1) you don't consume the resources of a System.Threadin g.Timer, and
2) you don't waste time using ThreadPool threads that aren't going to be
able to read any data anyway (which happens most of the time when you
poll).
Async delegates/callbacks make for a much cleaner program structure in
my opinion.
Using asynchronous delegates with Windows Forms isn't difficult at all.
All you need to remember is that you make sure you synchronise access to
your UI elements (remember: never access UI objects from a thread other
than the UI thread - Control.Invoke( ) and Control.InvokeR equired).
If your scanning library doesn't provide support for asynchronous
reading of data, well, there may be other ways but it all depends on how
your library is implemented. You might be able to make a blocking call
in another thread or something.
Regards,
-Adam.
Viet wrote: I have a couple of questions that hopefully someone could clarify for
me. I have an app that uses the threading.timer to constantly poll a scanner
to scan in documents. I understand that Async delegates can also be used
for polling purposes. Would it be more efficient to use async delegates in
this case? Are their any examples on how to use this under vb.net forms?
Thanks,
Jonathan