Hot File

Generating synchronous method stubs from asynchronous method pairs

View: 2733    Dowload: 0   Comment: 0   Post by: naruto  
Author: none   Category: Development Tools   Fields: Other

0 point/4 review File has been tested

Download   generating-synchronous-method.zip (136.96 KB)

You need to Sign In to download the file generating-synchronous-method.zip
If you do not have an account then Sign up for free here

Download error   Report copyright violation

During the development of a GSM Modem API, I found I was repeating a lot of code for encapsulating the synchronous versions of asynchronous method templates. The common pattern for such code implements asynchronous methods with the same name as the synchronous versions, by prefixing the begin and end method with 'Begin' and 'End', respectively. This means that for each set of two asynchronous method pairs, you need another method to synchronize them - in a library of any significant size, this makes for considerably more work. This article explains how to write a custom tool which utilises the content of the asynchronous class, to generate all the synchronous stubs, for methods which match the naming convention. Because I have found this custom tool so helpful, I have folded it into the Missing Bits product. You can search for this product on CodeProject to obtain a copy containing a version of this custom tool along with many other useful additions to Visual Studio.

Introduction

Background and Prerequisites

This article is not a tutorial on asynchronous programming, merely an overview on utilising this particular custom tool. A basic understanding of Custom Tools would be greatly helpful; however, everything is provided in the zip file for Visual Studio 2005 registration.

Basic Architecture

This custom tool is designed to be applied to a code file containing a single class, wherein are one or more method signatures matching the required asynchronous code pattern. The custom tool then parses these methods, determining from their parameters and return types, what the synchronous method should look like.

Method Pattern

Both the beginner, and completion, async methods must conform to the following patterns so that the custom tool may identify, and interpret them.

The following example uses a basic read operation to demonstrate method signatures that will be recognised by the custom tool.

Example Begin Method

public IAsyncResult BeginRead(byte[] buffer, 
       int length, int offset, AsyncCallback callback, object state)

The method must return IAsyncResult, and the last two arguments must be AsyncCallback, and an object for state.

Example End Method

public int EndRead(IAsyncResult result)

The method returns the same type as the synchronous version, and takes just the IAsyncResult as the sole argument.

Code generated by the Custom Tool follows:

public virtual int Read( byte[] buffer, int length, int offset) {
    System.IAsyncResult result = base.BeginRead(buffer, length, offset, null, null);
    return base.EndRead(result);
}

Installation

The SynchronizerCustomTool assembly must be installed in the GAC, then run the reg file to install the required Registry keys. Then, to use the custom tool, set the 'Custom Tool' property of your C# code file to "SynchronizerCustomTool" - this will result in the generation of another C# code file containing the synchronized methods.

Generating synchronous method stubs from asynchronous method pairs

Generating synchronous method stubs from asynchronous method pairs Posted on 13-05-2014  During the development of a GSM Modem API, I found I was repeating a lot of code for encapsulating the synchronous versions of asynchronous method templates. The common pattern for such code implements asynchronous methods with the same name as the synchronous versions, by prefixing the begin and end method with 'Begin' and 'End', respectively. This means that for each set of two asynchronous method pairs, you need another method to synchronize them - in a library of any significant size, this makes for considerably more work. This article explains how to write a custom tool which utilises the content of the asynchronous class, to generate all the synchronous stubs, for methods which match the naming convention. Because I have found this custom tool so helpful, I have folded it into the Missing Bits product. You can search for this product on CodeProject to obtain a copy containing a version of this custom tool along with many other useful additions to Visual Studio. 5/10 2733

Comment:

To comment you must be logged in members.

Files with category

  • Changes in Programmer Tools' Infrastructure

    View: 2941    Download: 0   Comment: 0   Author: none  

    Changes in Programmer Tools' Infrastructure

    Category: Development Tools
    Fields: Other

    0.75/6 review
    The article describes some observations concerning changes in the infrastructure of tools used by programmers in everyday work. First of all, these changes are related to the release of Visual Studio 2010.

  • An Overview of the NuGet Ecosystem

    View: 3336    Download: 0   Comment: 0   Author: none  

    An Overview of the NuGet Ecosystem

    Category: Development Tools
    Fields: none

    0.64285714285714/7 review
    NuGet is a free, open source package management system for .NET and consists out of a few client tools (NuGet Command Line and NuGet Visual Studio Extension) and the official NuGet Gallery hosted at http://www.nuget.org/. Combined, these tools and...

  • Folder Listener: A Tool to Watch File System Activity in any Folder

    View: 3085    Download: 5   Comment: 0   Author: none  

    Folder Listener: A Tool to Watch File System Activity in any Folder

    Category: Development Tools
    Fields: none

    1.5/3 review
    Most of the time when you are doing some development or testing, you might need to know what changes are made in a particular folder. This requirement frequently arises when you are testing /developing software that copies /delete files in the...

  • Generating synchronous method stubs from asynchronous method pairs

    View: 2733    Download: 0   Comment: 0   Author: none  

    Generating synchronous method stubs from asynchronous method pairs

    Category: Development Tools
    Fields: Other

    0/4 review
    During the development of a GSM Modem API, I found I was repeating a lot of code for encapsulating the synchronous versions of asynchronous method templates. The common pattern for such code implements asynchronous methods with the same name as the...

  • How to Minify js and CSS file using Visual Studio 2012

    View: 1742    Download: 0   Comment: 0   Author: none  

    How to Minify js and CSS file using Visual Studio 2012

    Category: Development Tools
    Fields: Other

    1.125/4 review
    In my previous article I have talked about what is Microsoft’s Web Optimization Framework and how to use this framework in Asp.net web form application. There are two pillars of this framework bundling and minification. So this framework...

  • A New Approach to Designing Web Applications

    View: 3692    Download: 0   Comment: 0   Author: none  

    A New Approach to Designing Web Applications

    Category: Development Tools
    Fields: Other

    0/8 review
    With all the hay being made about UML modeling, you'd think that was the only way to design an application. I've got news for you. It's the wrong approach. Now, before you flame me for my heresy, read the rest of this paragraph. Much like the 60%...

  • How to install SNMP extension agent DLL

    View: 2093    Download: 0   Comment: 0   Author: none  

    How to install SNMP extension agent DLL

    Category: Development Tools
    Fields: none

    0/20 review
    This tutorial is the second part of my previous article "How to develop a SNMP extension agent DLL". Here I shall explain how to install the developed SNMP extension agent DLL in Windows 2000. This agent DLL is from the previous part of this...

  • The Web Developer Checklist : A One-Stop-Shop for Improving the Web

    View: 2574    Download: 0   Comment: 0   Author: none  

    The Web Developer Checklist : A One-Stop-Shop for Improving the Web

    Category: Development Tools
    Fields: Education - Schools

    0/1 review
    I’ve been searching for some time for a single resource that I could go to check a variety of best-practices and methods of improving the performance of my sites and applications and I can now mark that off of my list.

 
Newsletter Email

File suggestion for you

File top downloads

logo codetitle
Codetitle.com - library source code to share, download the file to the community
Copyright © 2015. All rights reserved. codetitle.com Develope by Vinagon .Ltd