.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How to run multiple methods asyncronously and wait until all are finished?

Posted By:      Posted Date: September 10, 2010    Points: 0   Category :.NET Framework
I have this method:   public virtual List<User> GetUsersAsync(string[] usernames) { var result = new List<User>(); foreach (var username in usernames) { result.Add(this.GetUser(username)); } return result; }   Currently this method and GetUser run synchronously. How can I change this so that each GetUser runs asynchronously and GetUsers returns when all the GetUser() requests are completed? I know one way would be using delegate beginInvoke and endInvoke like this:   public virtual List<User> GetUsers(string[] usernames) { var result = new List<User>(); var delegates = new Dictionary<GetUserDelegate, IAsyncResult>(); // begin invoke all asynchronously foreach (var username in usernames) { var thisDelegate = new GetUserDelegate(GetUser); var asyncResult = thisDelegate.BeginInvoke(username, null, null); delegates.Add(thisDelegate, asyncResult); } // end invoke all foreach (var thisDelegate in delegates) { result.Add(thisDelegate.Key.EndInvoke(thisDelegate.Value)); } return result; }   this does work but seems to be a bit ugly code; what is the better way to do this? Thanks  

View Complete Post

More Related Resource Links

Multiple web methods in one transaction


Hi everyone

Sorry I am kinda new in web services, so it may sound a bit newbish question.

We have a web service that comunicates with the database and exposes web methods that enables the application to access the database. Each method does only one operation (Insert, Update or Delete). What I need to do is create a transaction that will be consisted of multiple calls to the database, meaning multiple calls of more then one web methods. Can I do that? (I read that if the web method does not throw exception - or ContextUtil.SetAbort() is not called - the transaction will be commited automatically when the web method finishes executing, which I don't want to happen because I want to call another web method in the same transaction, and then manually commit the transaction)

Thank you in advance.

Execute Command and wait until finished (WMI - ManagementClass)

Hi allI am trying to execute a command on a remote maschineand wait until the command is finished.I can start the process but I do not know how to wait for finish.Thanks for any comment !!!Best regardsFrankHere is what I am doing            System.Management.ConnectionOptions local_Connection = new System.Management.ConnectionOptions();            local_Connection.Username = "some_user";            local_Connection.Password = "some_password";            local_Connection.Authority = "ntlmdomainome_domain";            // ManagementScope erstellen            System.Management.ManagementScope local_Scope = new System.Management.ManagementScope("\\\\servername\\root\\CIMV2", local_Connection);            local_Scope.Connect();            // ManagementClass erstellen            System.Management.ManagementClass local_ClassInstance = new System.Management.ManagementClass(local_Scope, new System.Management.ManagementPath("Win32_Process"), null);            // Create a results and completion handler            System.Management.ManagementOperationObserver local_ClassHandler = new System.Management.ManagementOperationObserver();            // Invoke method asynchronously            System.Management.ManagementBaseObject local_InParams = local_ClassInstance.GetMethodParameters("Create");            local_InParams["CommandLin

Accessing Multiple methods from a web service using web service task



When i am using an SSIS web service task, is it possible to get all the methods information to different tables.


Else if the above case is not possible, can i use multiple web service tasks with same http connection(.wsdl file) to access the web service for each method and then load the info to a table.(if i can do this, is there any performance issue)



Single Try/catch multiple methods


Hi All

I need to validate 3 different variables to see if they are valid dates and if they not tell me which one fails in the Catch.

 Method which takes a string and converts to datetime object below:-

public static DateTime dateConverter(string strDate)
            DateTime dt = new DateTime();

                if (strDate == "")
                    dt = Convert.ToDateTime("1900-01-01 00:00:00");
                    dt = DateTime.Parse(strDate).ToUniversalTime();

                return dt;
  static void Main()
                DateTime d = new DateTime();
                DateTime e;
                string w = "w";
                string valid = "2010-01-01 00:00:00";

                      d = dateConverter(w);
                      e = dateConverter(valid);
                catch(Exception c)
                   Console.WriteLine(*** "is a problem" + c.Data + c.Message + c.Source);



Where the *** in above I need which ever variable fails.

State Machine - Create AND wait for multiple tasks


After spending quite some time on this and researching every link I could find, I still am unable to make this work. I'd think this would be an every day case that many people encounter. Document approval with multiple reviewers.

But all the workflow examples I can find have one of two things in common. Either they are sequential and don't allow the workflow to revert to an earlier 'state/step' OR they are state machine but then only track one task at any point in time.

I need it to be a state machine since the workflow could go in circles between different groups of reviewers until they all agree. I need to be able in any given state, assign tasks to MULTIPLE users to review that document, and then also WAIT till ALL the users in that state have finished reviewing that document. Only then can it go to the next state and a different SET of reviewers. From there it might go back to the initial reviewers if they're not happy or it might move on to the next state.

I had tried using a replicator in the submit state to create multiple tasks for all the users (my replicator fired multiple times but only one task would get created). But then when I tried to create the second state to wait on all the tasks that were created, that was a whole other set of issues. I was also starting to go down the road of a statemachine triggering a bunch of sequentials but

Multiple database support with Entity Framework

One of the features introduced in Entity Framework is being database independent. Which mean each database provider can support Entity Framework by implementing its provider.

This feature allows you build applications independent from the underplaying database provider. In this post I'm going to show how to build an application that support multiple databases using same conceptual model made by Entity Framework.

The Decorator Pattern & Extension Methods

The decorator pattern provides a formal way to add new functionality to an existing type, without sub-classing. First question: What is wrong with classical inheritance? In and of itself, nothing is wrong with the good old Is-A relationship. It is very common to derive a new class from an existing base class in order to override a few virtual members, and add a pinch of new functionality.

Binding the multiple drop down boxes in GridView using JQuery in ASP.NET

Here is the code for binding the multiple drop down boxes in GridView using JQuery in ASP.NET

Upload Multiple File using JQuery in asp.net

In this article I have explained how to upload multiple files using file upload control. I have used jQuery plugin for uploading multiple files.

I have also explained how to check for file type, file maximum size limit using jQuery & also using server side validation code.

Using jQuery to directly call ASP.NET AJAX page methods

Here I am looking to explain how to call page methods using jQuery. Using jQuery to directly call ASP.NET AJAX page methods

Adding Multiple Columns and Rows in GridView without using a Database

This article describes on how to add multiple columns and rows in GridView without using a database. Basically the GridView will be populated with data based on the values entered in each TextBoxes on Button Click and retain the GridView data on post back.

GridView Multiple Filter AJAX Control

This AJAX control enables the user to filter data within any column inside a GridView. The user can add multiple filters and can delete existing ones too.

The Decorator Pattern & Extension Methods

Numerous design patterns exist in the software world today, and ultimately nothing is preventing you from making your own (if people buy into it or not is another question). Furthermore, there is no 'master list' of patterns that all developers agree upon. While this is true, if you pick up any book on the subject, you will find a set of very common patterns most programmers agree are very useful. Many of these patterns were first formalized in the seminal book on the subject, Design Patterns: Elements of Reusable Object-Oriented Software (aka, the Gang of Four [GOF] book; not to be confused with the UK punk band of the same name).

Multiple Column Dropdownlist for the ASP.NET DataGrid

Based on my previous control "Multiple Column DropDownList for ASP.NET", I received many emails asking for the same control to be used in the DataGrid for web applications. Here we go.. This control can be used as the regular MS DropDownList in the DataGrid and also as a regular dropdownlist. It has all the properties, like DataTextField, DataValueField, DataSource, SelectedIndex etc. The download file contains the samples both in VB.NET and C#. In this sample, I have used the Northwind database of SQL Server.

ASP.NET Multiple Selection DropDownList with AJAX HoverMenuExtender

Recently, I was looking for a multiple selection dropdownlist control for my new project. After spending some time researching for it, I decided to put together all my finding in one web user control. This web user control consists of an ASP.NET AJAX HoverMenuExtender, JavaScript, StyleSheet and CheckBoxListExCtrl . The final product will work with or without a MasterPage and you can drag and drop more than one instances of the control on to the page.

Xml File Methods and Properties

Method and Properties of XmlTextWriter class:
The XmlWriter class is a base class that outputs an XML data structure. It has methods to sequentially write XML elements in a proper hierarchy to create an XML file or other types of output streams. The System.Xml namespace provides support for the XmlWriter. It must be imported to the ASP.NET page with the directive

<%@ Import Namespace="System.Xml" %>

The XmlTextWriter

XmlWriter is an abstract class that is implemented as an extended XMLTextWriter class. The XmlTextWriter writes a sequence of XML nodes one element at a time. Output can be written to an XML file, although other streams of output data can be produced. It can create a new file or overwrite an existing file. Its non-cached writing techniques provides very fast generation of an output stream.

jquery autocomplete multiple values


i got some samples and i did autocomplete using jquery , its working well for single input values

but i need to pass multiples values after one by one in the textbox. Is it possible to pass multiple

values in the textbox for autocomplete in jquery in asp.net?


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend