<NME> MainWindow.xaml.cs
<BEF> ﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DotNetSiemensPLCToolBoxLibrary.Communication;
using DotNetSiemensPLCToolBoxLibrary.DataTypes;

namespace ExampleWPFVisualization
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private DotNetSiemensPLCToolBoxLibrary.Communication.PLCConnection myConn = null;
        public MainWindow()
        {
            InitializeComponent();
        }

        private void cmdConfig_Click(object sender, RoutedEventArgs e)
        {
            //Verbindung konfigurieren
            DotNetSiemensPLCToolBoxLibrary.Communication.Configuration.ShowConfiguration("ExampleWPFVisualization", true);
        }


        private void cmdConnect_Click(object sender, RoutedEventArgs e)
        {
            //Alle Tags in eine Liste packen
            List<PLCTag> Tags = new List<PLCTag>();
            foreach (DictionaryEntry dictionaryEntry in this.Resources)
            foreach (DictionaryEntry dictionaryEntry in this.Resources)
            {
                if (dictionaryEntry.Value is PLCTag)
                    Tags.Add((PLCTag) dictionaryEntry.Value);
            }

            try
                //Verbindungskonfig laden und Verbinden
                myConn = new PLCConnection("ExampleWPFVisualization");
                myConn.Connect();

                //Tags im Hintergrund laden
                if (worker != null)
                {
                    worker.CancelAsync();
                    worker.Dispose();
                }
                worker = new BackgroundWorker();
                worker.DoWork += delegate(object s, DoWorkEventArgs args)
                                     {
                                         while (true)
                                         {
                                             try
                                             {
                                                 myConn.ReadValues(Tags);
                                             }
                                             catch(Exception ex)
                                             { }
                                         }
                                     };

                worker.RunWorkerAsync();
            }
            catch(Exception ex)
            {
                lblStatus.Content = ex.Message;
            }
        }

        private void PLCTag_PropertyChanged(object sender, PropertyChangedEventArgs e)
                                         }
                                     }
                                 };

                    myConn.WriteValue((PLCTag) sender);
        }

      

      
            worker.CancelAsync();            
            cmdConnect.IsEnabled = true;
            cmdStop.IsEnabled = false;
            myConn.Disconnect();
        }


      

      
    }
}

<MSG> - Changes to WPF example, so it supports to break the Connection, or to Start the Visu, without the connection being available


<DFF> @@ -38,6 +38,9 @@ namespace ExampleWPFVisualization
 
         private void cmdConnect_Click(object sender, RoutedEventArgs e)
         {
+            cmdConnect.IsEnabled = false;
+            cmdStop.IsEnabled = true;
+
             //Alle Tags in eine Liste packen
             List<PLCTag> Tags = new List<PLCTag>();
             foreach (DictionaryEntry dictionaryEntry in this.Resources)
@@ -51,33 +54,34 @@ namespace ExampleWPFVisualization
                 //Verbindungskonfig laden und Verbinden
                 myConn = new PLCConnection("ExampleWPFVisualization");
                 myConn.Connect();
+            }
+            catch (Exception ex)
+            {
+                lblStatus.Content = ex.Message;
+            }
+            //Tags im Hintergrund laden
+            if (worker != null)
+            {
+                worker.Dispose();
+            }
 
-                //Tags im Hintergrund laden
-                if (worker != null)
-                {
-                    worker.CancelAsync();
-                    worker.Dispose();
-                }
-                worker = new BackgroundWorker();
-                worker.DoWork += delegate(object s, DoWorkEventArgs args)
+            worker = new BackgroundWorker();
+            worker.WorkerSupportsCancellation = true;
+            worker.DoWork += delegate(object s, DoWorkEventArgs args)
+                                 {
+                                     while (!worker.CancellationPending)
                                      {
-                                         while (true)
+                                         try
+                                         {
+                                             myConn.ReadValues(Tags);
+                                         }
+                                         catch (Exception ex)
                                          {
-                                             try
-                                             {
-                                                 myConn.ReadValues(Tags);
-                                             }
-                                             catch(Exception ex)
-                                             { }
                                          }
-                                     };
+                                     }
+                                 };
 
-                worker.RunWorkerAsync();
-            }
-            catch(Exception ex)
-            {
-                lblStatus.Content = ex.Message;
-            }
+            worker.RunWorkerAsync();
         }
 
         private void PLCTag_PropertyChanged(object sender, PropertyChangedEventArgs e)
@@ -88,6 +92,13 @@ namespace ExampleWPFVisualization
                     myConn.WriteValue((PLCTag) sender);
         }
 
+        private void cmdStop_Click(object sender, RoutedEventArgs e)
+        {
+            worker.CancelAsync();            
+            cmdConnect.IsEnabled = true;
+            cmdStop.IsEnabled = false;
+        }
+
       
 
       

- Changes to WPF example, so it supports to break the Connection, or to Start the Visu, without the connection being available