Skip Navigation Links
Home
Forum Home
Latest 50
Unanswered
Win Prizes
All Time Leaders
Jump to CategoryExpand Jump to Category
Login 
    Welcome Guest!
 Search Forum For :  
X
 Login
Please login to submit a new post, reply and edit exiting posts, see user profiles, and access more features. If you are not a registered member, Register here.
User Id / Email:
Password:  
Forgot Password | Forgot UserName
   Home » C# Language » Background worker & Serial Comms
       
Author Reply
Glenn Patton
posted 58 posts
since Dec 08, 2011 
from

Background worker & Serial Comms

  Posted on: 03 Feb 2012       
Hi All,

I am on the "make it work quicker" portion on a project to upload and download sets of values from a device via a USB comm port.  The hard parts are all done now on to the clean up.  I was wondering if the backgroundWorker component could be used to remove the need I have for an Application.DoEvents(); I have used the VB6 version in the past to mixed results from "it works!" to "its broken <expletive deleted>!!". 

Is there any benefit to operating the interrupt handler (which is on a seperate thread I believe) on the backgroundWorker or all the Serial Comms on the background thread. Using invokes to get the data from the Worker.  

Glenn
Vulpes
posted  5113 posts
since  Feb 28, 2011 
from 

 Re: Background worker & Serial Comms
  Posted on: 03 Feb 2012   Accepted Answer     0  
You can use a BackgroundWorker to keep the UI responsive whilst you're carrying out a long running task. This then avoids the need to call Application.DoEvents().

However, it may not be an ideal solution for a serial comms application because the SerialPort's DataReceived, ErrorReceived and PinChanged events are all called on a secondary thread anyway - different from the thread used by the BackgroundWorker - so you might have the additional problem of synchronizing between these two threads as well as the UI thread.
Sam Hobbs
posted  6447 posts
since  Sep 07, 2009 
from  Los Angeles, California, USA

 Re: Background worker & Serial Comms
  Posted on: 03 Feb 2012        0  
Serial communications need to be done with threads. DoEvents is a solution developed for unmanaged VB since unmanaged VB does not do threads. DoEvents is not the ideal solution. One way of explaining that DoEvents is not the ideal solution is to say that it executes when your program executes, not when the device needs attention. DoEvents can work when the UI needs attention occasionally but a serial device needs your program to be more responsive.

I am not sure if a background worker is good for that. I would use the threading API directly instead. I admit however that I am not familiar with the manged API for serial communications; does it include a separate thread as a part of the library? I assume not but if I am wrong then some of what I am saying would not be relevant. A reasonable design would include two threads; one each for input and output. You could use a background worker to manage them and interface with the UI. You should make the serial IO independent of the UI.

If you can write code that depends on .Net version 4, there is a new set of classes (Tasks) that can make multithreading easier.
Thinking is a feeling; pleasant for some and unpleasant for others.
Glenn Patton
posted  58 posts
since  Dec 08, 2011 
from 

 Re: Background worker & Serial Comms
  Posted on: 06 Feb 2012        0  
Hi, Thanks for that, just got to persuade people to pay for VS2010!! Glenn
       
Top Articles
View all »
Team Foundation Server Hosting
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Advertise with us
Current Version: 5.2011.3.12
 © 1999 - 2012  Mindcracker LLC. All Rights Reserved