473,737 Members | 7,206 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 6212
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 continue to process? Or would they
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 polled to check for completion. 2. The Begin function would take a callback, and the async process...
10
2956
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 polled to check for completion. 2. The Begin function would take a callback, and the async process would
2
1174
by: Viet | last post by:
Can I use Async delegates to do infinite polling in vb.net?
0
988
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
8610
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' functions. I already found that connecting doesn't set the "isconnected" variable correctly...
13
1973
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 be creating a single thread manulally (or using threadpool) and and setting the polling on an...
2
3765
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 IAsynchResult.IsCompleted property on each task and update the UI without re-initializing my...
0
8968
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8787
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9208
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6750
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4824
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.