473,544 Members | 1,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Async Delegates polling for vb.net examples

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

Nov 21 '05 #1
2 6197
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


Nov 21 '05 #2
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


Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

39
789
by: jabailo | last post by:
I am looping through a text file, and with each row, I launch a web service, asynchronously. Before I move on to the next step in the process, I want to make sure that all the web services have completed. How can I do this? If I were to just put a Thread.Sleep with some arbitrary number ( say 5 minutes ) would the asynch web services...
4
339
by: Stephen | last post by:
I am new to C# and can't get my head round what delegates are and what they are for. can anyone enlighten me?
0
274
by: Shawn Meyer | last post by:
Hello - I am trying to write a class that has an async BeginXXX and EndXXX, plus the regular XXX syncronous method. Delegates seemed like the way to go, however, I still am having problems getting exactly what I want. Here are my goals 1. I would like the IAsyncResult that is returned by the Begin function to be able to be waited on or...
10
2935
by: Shawn Meyer | last post by:
Hello - I am trying to write a class that has an async BeginX and EndX, plus the regular X syncronous method. Delegates seemed like the way to go, however, I still am having problems getting exactly what I want. Here are my goals 1. I would like the IAsyncResult that is returned by the Begin function to be able to be waited on or...
2
1167
by: Viet | last post by:
Can I use Async delegates to do infinite polling in vb.net?
0
984
by: Viet | last post by:
I understand that Asynchronous delegates can be used to poll but most of the examples show the polling being done for a specified period of time. Are there any examples in VB.NET forms that show the polling being done indefinitely??
11
8582
by: atlaste | last post by:
Hi, In an attempt to create a full-blown webcrawler I've found myself writing a wrapper around the Socket class in an attempt to make it completely async, supporting timeouts and some scheduling mechanisms. I use a non-blocking approach for this, using the call to 'poll' to support the async mechanism - rather than the 'begin' and 'end'...
13
1957
by: Dog Ears | last post by:
I've got a windows form that monitors the status of employees it polls a database every 2 seconds to fetch updates then update a underlying dataset bound to a grid using Invoke to marshal to the gui thread. What pattern should I be using now I'm upgrading to .net 2.0? APM, async delegates and BeginInvoke or Thread.Start etc...? Should I...
2
3757
by: =?Utf-8?B?RGF2ZQ==?= | last post by:
I'm using an async page to kick off a couple of asynchronous web services using the PageAsyncTask class. I'm also testing a progress bar that uses an Ajax UpdatePanel and Timer control to postback every 5 or 10 seconds and increment the progress. However, Is there a way to merge these two concepts so that I can check the status of the...
0
7414
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7757
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7360
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7699
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5288
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4905
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3398
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
651
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.