Example #1
0
        //[OperationBehavior(TransactionScopeRequired = true)]
        private async void GetInfoBtn_Click(object sender, RoutedEventArgs e)
        {
            IEnumerable <ZipCityData> cityBatch = new List <ZipCityData>()
            {
                new ZipCityData {
                    ZipCode = "70112", City = "Who Data Nation"
                },
                new ZipCityData {
                    ZipCode = "30313", City = "Next SuperBowl"
                },
                new ZipCityData {
                    ZipCode = "02035", City = "Cheat City"
                },
                new ZipCityData {
                    ZipCode = "33056", City = "Dan Marino City"
                }
            };

            ZipCodeLsb.Items.Clear();

            // in order to prevent deadlock it has to put tis instructions in another thread
            // to free the UI thread
            await Task.Run(() =>
            {
                try
                {
                    //All the action has to belong to a different thread otherwise after the first callback
                    // it will result in a deadlock
                    GeoCallbackServiceClient proxy = new GeoCallbackServiceClient(new InstanceContext(this));
                    proxy.Open();

                    proxy.UpdateZipCity(cityBatch.ToList());
                    proxy.Close();

                    MessageBox.Show("Updated");
                }
                catch (FaultException ex)
                {
                    MessageBox.Show($"Error: {ex.Message}");
                }
            });
        }
Example #2
0
        private async void RestoreDataBtn_Click(object sender, RoutedEventArgs e)
        {
            IEnumerable <ZipCityData> cityBatch = new List <ZipCityData>()
            {
                new ZipCityData {
                    ZipCode = "70112", City = "New Orleans"
                },
                new ZipCityData {
                    ZipCode = "30313", City = "Atlanta"
                },
                new ZipCityData {
                    ZipCode = "02035", City = "Foxborough"
                },
                new ZipCityData {
                    ZipCode = "33056", City = "Miami"
                }
            };

            ZipCodeLsb.Items.Clear();

            await Task.Run(() =>
            {
                try
                {
                    GeoCallbackServiceClient proxy = new GeoCallbackServiceClient(new InstanceContext(this));
                    proxy.Open();

                    proxy.UpdateZipCity(cityBatch.ToList());
                    proxy.Close();

                    MessageBox.Show("Restored");
                }
                catch (FaultException ex)
                {
                    MessageBox.Show($"Error: {ex.Message}");
                }
            });

            MessageBox.Show("finish");
        }