/// <summary> /// Retrieves the Servers URI for a given profile asynchronously. /// </summary> /// <param name="profile"></param> /// <param name="taskId"></param> /// <remarks> /// This method starts an asynchronous command. /// First, it checks the supplied task ID for uniqueness. /// If taskId is unique, it creates a new WorkerEventHandler /// and calls its BeginInvoke method to start the calculation. /// </remarks> public virtual void GetServersAsync( string profile, int timeout = DEFAULT_TIMEOUT, object taskId = null) { if (taskId == null) { taskId = System.Guid.NewGuid(); } // Create an AsyncOperation for taskId. AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(taskId); // Multiple threads will access the task dictionary, // so it must be locked to serialize access. lock (userStateToLifetime.SyncRoot) { if (userStateToLifetime.Contains(taskId)) { throw new ArgumentException( "Task ID parameter must be unique", "taskId"); } userStateToLifetime[taskId] = asyncOp; } // Start the asynchronous operation. GetServersWorkerEventHandler workerDelegate = new GetServersWorkerEventHandler(CalculateGetServersWorker); workerDelegate.BeginInvoke(profile, timeout, asyncOp, null, null); }
/// <summary> /// Retrieves the Servers URI for a given profile asynchronously. /// </summary> /// <param name="profile"></param> /// <param name="taskId"></param> /// <remarks> /// This method starts an asynchronous command. /// First, it checks the supplied task ID for uniqueness. /// If taskId is unique, it creates a new WorkerEventHandler /// and calls its BeginInvoke method to start the calculation. /// </remarks> public virtual void GetServersAsync( string profile, int timeout = DEFAULT_TIMEOUT, object taskId = null) { if (taskId == null) { taskId = System.Guid.NewGuid(); } // Create an AsyncOperation for taskId. AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(taskId); // Multiple threads will access the task dictionary, // so it must be locked to serialize access. lock (userStateToLifetime.SyncRoot) { if (userStateToLifetime.Contains(taskId)) { throw new ArgumentException( "Task ID parameter must be unique", "taskId"); } userStateToLifetime[taskId] = asyncOp; } // Start the asynchronous operation. GetServersWorkerEventHandler workerDelegate = new GetServersWorkerEventHandler(CalculateGetServersWorker); workerDelegate.BeginInvoke(profile, timeout, asyncOp, null, null); }