Example #1
0
        /// <summary>
        /// Background worker thread that does the service call
        /// </summary>
        /// <param name="sender">sender not used</param>
        /// <param name="e">ServiceCommandAsync arguments</param>
        private void bwMainDoWork(object sender, DoWorkEventArgs e)
        {
            ServiceCommandAsync serviceCommandAsync = (ServiceCommandAsync)e.Argument;

            serviceCommandAsync.Result = InvokeServiceCommand(serviceCommandAsync.ServiceCommandData);
            e.Result = serviceCommandAsync;
        }
Example #2
0
        /// <summary>
        /// Background worker completed
        /// </summary>
        /// <param name="sender">sender not used</param>
        /// <param name="e">ServiceCommandAsync parameters containing the results and information required for the callback</param>
        private void bwMainRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            string          response = "";
            Action <string> callback = null;
            string          type     = "";

            if (e.Cancelled)
            {
                response = "Cancelled";
            }
            else if (e.Error != null)
            {
                ServiceCommandAsync serviceCommandAsyncResult = (ServiceCommandAsync)e.Result;
                response = String.Format("<Error><Message>{0}</Message></Error>", e.Error.Message);
            }
            else
            {
                ServiceCommandAsync serviceCommandAsyncResult = (ServiceCommandAsync)e.Result;
                response = serviceCommandAsyncResult.Result;
                callback = serviceCommandAsyncResult.Callback;
                type     = serviceCommandAsyncResult.ServiceCommandData.Noun;
            }

            InvokeServiceReturn(response, type, callback);
        }
Example #3
0
        /// <summary>
        /// Invoke Services async
        /// </summary>
        /// <param name="serviceCommand">The Service Command</param>
        /// <param name="callback">Method to callback to handle the sendtoclient message</param>
        public void InvokeServiceAsync(ServiceCommand serviceCommand, Action <string> callback)
        {
            ServiceCommandAsync serviceCommandAsync = new ServiceCommandAsync();

            serviceCommandAsync.ServiceCommandData = serviceCommand;
            serviceCommandAsync.Callback           = callback;

            mBackgroundWorkerServiceCall = new BackgroundWorker();
            mBackgroundWorkerServiceCall.WorkerSupportsCancellation = false;
            mBackgroundWorkerServiceCall.DoWork             += new DoWorkEventHandler(bwMainDoWork);
            mBackgroundWorkerServiceCall.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bwMainRunWorkerCompleted);
            mBackgroundWorkerServiceCall.RunWorkerAsync(serviceCommandAsync);
        }