/// <summary> /// Executes a method in a new thread /// </summary> /// <param name="requestId">The request id</param> /// <param name="action">Some action</param> /// <returns> /// SiLAReturnValue /// </returns> protected SiLAReturnValue ExecuteAsync(int requestId, SiLAAction action) { Tools.WriteLogLine("Executing {0} ", this.Requests.FirstOrDefault(r => r.RequestId == requestId)); Thread thread = new Thread(() => { Tools.WriteLogLine("... {0} thread", this.Requests.FirstOrDefault(r => r.RequestId == requestId)); SiLAReturnValue retValue = action(false); Tools.WriteLogLine("... {0} completed", this.Requests.FirstOrDefault(r => r.RequestId == requestId)); try { SiLARequest request = this.Requests.FirstOrDefault(r => r.RequestId == requestId); if (request != null) { Tools.WriteLogLine("... {0} ResponseEvent", this.Requests.FirstOrDefault(r => r.RequestId == requestId)); this.Requests.Remove(request); string responseDataString = Tools.CreateXML(retValue.GetResponseData()); EventReceiverClient eventClient = new EventReceiverClient("EventReceiver_EventReceiver"); eventClient.Endpoint.Address = new System.ServiceModel.EndpointAddress(this.EventReceiverURI); eventClient.ResponseEvent(requestId, retValue, responseDataString); eventClient.Close(); } } catch (Exception ex) { retValue.returnCode = (int)ReturnCode.FinishedWithWarning; retValue.message = ex.Message; this.State = Status.errorHandling; Tools.WriteLogLine("ERROR: {0}", ex); if (ex.InnerException != null) { Tools.WriteLogLine(" INNER: {0}", ex.InnerException); } } }); // sets result and return value to AsynchronousCommandAccepted SiLAReturnValue returnValue = action(true); // starts the thread thread.Start(); return(returnValue); }
/// <summary> /// Executes a method in a new thread /// </summary> /// <param name="requestId">The request id</param> /// <param name="action">Some action</param> /// <returns> /// SiLAReturnValue /// </returns> protected SiLAReturnValue ExecuteAsync(int requestId, SiLAAction action) { Tools.WriteLogLine("Executing {0} ", this.Requests.FirstOrDefault(r => r.RequestId == requestId)); Thread thread = new Thread(() => { Tools.WriteLogLine("... {0} thread", this.Requests.FirstOrDefault(r => r.RequestId == requestId)); SiLAReturnValue retValue = action(false); Tools.WriteLogLine("... {0} completed", this.Requests.FirstOrDefault(r => r.RequestId == requestId)); try { SiLARequest request = this.Requests.FirstOrDefault(r => r.RequestId == requestId); if (request != null) { Tools.WriteLogLine("... {0} ResponseEvent", this.Requests.FirstOrDefault(r => r.RequestId == requestId)); this.Requests.Remove(request); string responseDataString = Tools.CreateXML(retValue.GetResponseData()); EventReceiverClient eventClient = new EventReceiverClient("EventReceiver_EventReceiver"); eventClient.Endpoint.Address = new System.ServiceModel.EndpointAddress(this.EventReceiverURI); eventClient.ResponseEvent(requestId, retValue, responseDataString); eventClient.Close(); } } catch (Exception ex) { retValue.returnCode = (int)ReturnCode.FinishedWithWarning; retValue.message = ex.Message; this.State = Status.errorHandling; Tools.WriteLogLine("ERROR: {0}", ex); if (ex.InnerException != null) { Tools.WriteLogLine(" INNER: {0}", ex.InnerException); } } }); // sets result and return value to AsynchronousCommandAccepted SiLAReturnValue returnValue = action(true); // starts the thread thread.Start(); return returnValue; }