Ejemplo n.º 1
0
        private void ExecuteOperation(ThreadTerminator currentTerminator)
        {
            lock (sync)
            {
                MoneyConverterClient wcfClient = new MoneyConverterClient();

                try
                {
                    wcfClient.Open();
                    method.Invoke(wcfClient);
                    wcfClient.Close();

                    currentTerminator.ThrowIfCancellationRequested();
                }
                catch (TimeoutException timeout)
                {
                    JobState.Invoke(jobTimeout);
                    wcfClient.Abort();
                }
                catch (CommunicationException commException)
                {
                    JobState.Invoke(jobCommunicationException);
                    wcfClient.Abort();
                }
            }
        }
Ejemplo n.º 2
0
        private void DoWork(object currentTerminator)
        {
            ThreadTerminator localTerminator = (ThreadTerminator)currentTerminator;

            try
            {
                // while (true)
                {
                    localTerminator.ThrowIfCancellationRequested();

                    try
                    {
                        ExecuteOperation(localTerminator);
                    }
                    finally
                    {
                        /* any required cleanup */
                        JobState.Invoke(jobComplete);
                    }
                }
            }
            catch (OperationCanceledException)
            {
                // write log that operation
                // execution have been canceled
                JobState.Invoke(jobCanceled);
            }
        }