WPF sample

Oct 26, 2010 at 7:10 PM

I want to use the Xcoordination Application Space in a WPF application, so I bult a simple demo program based upon the Winforms Interaction sample.

I used Visual Studio 2010 and

1) created a standard WPF application.

2) Added Worker.cs from the Winforms Interaction sample.

3) Changed MainWindow.xaml to:

<Window x:Class="KDPFlasher.MainWindow"
        Title="MainWindow" Height="350" Width="525">
        <Button Height="50" Content="Start" Click="Button_Click"></Button>
        <TextBox Name="Status" Height="50" Text="undefined" FontSize="18"></TextBox>
4) Changed MainWindow.xaml.cs to:
using System;
using System.Windows;
using Microsoft.Ccr.Core;
using XcoAppSpaces.Core;

namespace KDPFlasher
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
        private readonly Port<Port<int>> notifer;
        private readonly Port<int> notificationPort;

        public MainWindow()
            XcoAppSpace space = new XcoAppSpace();
            var w = space.RunWorker<NotificationWorkerNotificationWorker>();

            this.notifer = w;
            this.notificationPort = new Port<int>();
            space.Receive(this.notificationPort, this.OnNotification, SyncContext.UseCurrentSyncContext);

        void OnNotification(int i)
            this.Status.Text = i.ToString();

        private void Button_Click(object sender, RoutedEventArgs e)


        private void Window_Closing(object sender, EventArgs e)
            // We need to dispose of the Worker.

Everything works with the exception of the fact that when the WPF window is closed the worker thread continues to run. There must be some way to kill it but I do not know the proper way.
I will be happy to fix the demo is someone suggests a way to kill this thread and cleanup gracefully. Also I will be happy to share all this code if someone from the project team would like to include it in the demos.
Oct 29, 2010 at 7:38 AM


The worker doesn't have its own thread, but what actually continues to run are the threads of the CCR Dispatcher manage by the XcoAppSpace instance. Therefore what you need to do when closing the window is calling the XcoAppSpace's Dispose() method (just store your space object in a class variable).

We would be happy to include a WPF interaction demo into our usage demos, if you want to share your code.