Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

TLS: An exercise in concurrent programming

, 11 May 2008 CPOL
A walkthough about multi-threading an app and a useful helper class
<Window x:Class="TLS.Window1"
    Title="Thread Local Storage Demo"
    Height="300" Width="450">

            <ColumnDefinition Width="auto"/>
            <ColumnDefinition Width="*"/>
            <RowDefinition Height="auto" />
            <RowDefinition Height="*" />

            <Style TargetType="TextBlock">
                <Setter Property="Margin" Value="5" />
            <local:RunningConverter x:Key="RunningConverter" />
            <local:IntConverter x:Key="IntConverter" />

        <Border Grid.Column="0" Grid.Row="0" Margin="10" BorderThickness="1" BorderBrush="Black" CornerRadius="10">
            <ListBox Name="_ListBox" BorderThickness="0" Margin="10" MinWidth="100" ItemsSource="{x:Static local:TestInfo.Tests}">
                        <StackPanel Orientation="Horizontal">
                                <Style TargetType="TextBlock">
                                    <Setter Property="Margin" Value="3" />
                            <TextBlock Text="{Binding Attribute.Index}" />
                            <TextBlock Text="{Binding Attribute.Name}" />

        <Border Grid.Column="1" Grid.Row="0" Margin="10" BorderThickness="1" BorderBrush="Black" CornerRadius="10">
            <Grid Margin="10" DataContext="{Binding ElementName=_ListBox, Path=SelectedItem}">
                    <ColumnDefinition Width="auto" />
                    <ColumnDefinition Width="*" />
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />

                <TextBlock Grid.Column="0" Grid.Row="0" Text="Test:" />
                <TextBlock Grid.Column="0" Grid.Row="1" Text="Run:" VerticalAlignment="Center" />
                <TextBlock Grid.Column="0" Grid.Row="2" Text="Ops / sec / core :" />
                <TextBlock Grid.Column="0" Grid.Row="3" Text="Ops / sec   total :" />
                <TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding Attribute.Name}" />
                <TextBlock Grid.Column="1" Grid.Row="2" Text="{Binding OperationsPerSecondPerCore, Converter={StaticResource IntConverter}}" />
                <TextBlock Grid.Column="1" Grid.Row="3" Text="{Binding OperationsPerSecond, Converter={StaticResource IntConverter}}" />
                <Button Grid.Column="1" Grid.Row="1" Name="btnStop" Width="80" Margin="0,10"
                        Content="{Binding ElementName=Window, Path=Running, Converter={StaticResource RunningConverter}}"
                        HorizontalAlignment="Left" VerticalAlignment="Center" Padding="10,3"/>
        <ProgressBar Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1" Margin="10" Name="_ProgressBar" Height="42" VerticalAlignment="Center" />


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Nicholas Butler

United Kingdom United Kingdom

I built my first computer, a Sinclair ZX80, on my 11th birthday in 1980.
In 1992, I completed my Computer Science degree and built my first PC.
I discovered C# and .NET 1.0 Beta 1 in late 2000 and loved them immediately.
I have been writing concurrent software professionally, using multi-processor machines, since 1995.
In real life, I have spent 3 years travelling abroad,
I have held a UK Private Pilots Licence for 20 years,
and I am a PADI Divemaster.
I now live near idyllic Bournemouth in England.
If you would like help with multithreading, please contact me via my website:
I can work 'virtually' anywhere!

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150326.1 | Last Updated 11 May 2008
Article Copyright 2008 by Nicholas Butler
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid