/// <summary> /// Retrieves the Profile URI for a given entity asynchronously. /// </summary> /// <param name="command"></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 GetProfileAsync( string entity, 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. GetProfileWorkerEventHandler workerDelegate = new GetProfileWorkerEventHandler(CalculateGetProfileWorker); workerDelegate.BeginInvoke(entity, timeout, asyncOp, null, null); }
/// <summary> /// Retrieves the Profile URI for a given entity asynchronously. /// </summary> /// <param name="command"></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 GetProfileAsync( string entity, 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. GetProfileWorkerEventHandler workerDelegate = new GetProfileWorkerEventHandler(CalculateGetProfileWorker); workerDelegate.BeginInvoke(entity, timeout, asyncOp, null, null); }