Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 19th, 2005, 10:17 AM
Registered User
 
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Asynchronous Functions in C#

I have written a class in c# that uses the MSComm lib for serial communications to make calls to a remote device and retrieve data. The class has a method that when called, is writing the dial string to the port causing the modem to dial out and is then using the OnComm event to detect when the required data has come in and in case the data is correct it raises an event that also passes the data to the calling class which in turn calls another method of the comm class to terminate the call.

I would like to implement a calling class that loops through a number of such remote devices and for each one it performs the function described above. How can I implement this? It appears to me that in every iteration the loop has to wait for the event to be fired and if the data passed is correct it must terminate the call and move to the next iteration. How can I best implement such an operation?


Truly grateful for any help.


Regards

Chris

 
Old July 23rd, 2005, 07:53 PM
Authorized User
 
Join Date: May 2004
Posts: 83
Thanks: 0
Thanked 1 Time in 1 Post
Default

Besides how the specified functionality should be implemented, consider using asynchronous method calls if you want to be able to call a method and continue execution without waiting for it to return and be automatically notified when it does.

You can call every .NET method asynchronously by simply defining a delegate of the same signature as the method that is to be called asynchronously. After instantiating the delegate, you'll notice that for each method of your class, there's a pair of methods BeginXXX and EndXXX, where XXX is the name of the methods. These methods are used to asynchronously invoke and end the XXX method. When an asynchronous method call returns, you will be notified by means of a specified callback method.

Of course this is rather superficial discussion. I just wanted to point you to the right direction. Plz see the .NET documentation to learn how to implement this functionality.

Regards,

ejan
 
Old July 25th, 2005, 12:31 AM
Registered User
 
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks

I will try this and let you know,

Chris






Similar Threads
Thread Thread Starter Forum Replies Last Post
Asynchronous Transactions jroxit Other Programming Languages 0 July 29th, 2008 11:12 AM
Asynchronous call tapan General .NET 1 April 27th, 2007 08:12 AM
synchronous and asynchronous methods mike_remember ASP.NET 1.0 and 1.1 Professional 1 December 28th, 2006 10:52 AM
XSLProcessor asynchronous transformations Vx BOOK: Professional Ajax ISBN: 978-0-471-77778-6 1 September 5th, 2006 12:41 PM
2 questions about asynchronous callbacks pooh2006 ASP.NET 2.0 Professional 0 March 24th, 2006 11:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.