[索引页]
[源码下载]
作者:webabcd
介绍
Silverlight 2.0 使用Thread,ThreadPool来实现多线程开发
Thread - 用于线程的创建和控制的类
Timer - 用于以指定的时间间隔执行指定的方法的类
BackgroundWorker - 用于在单独的线程上运行操作
ThreadPool - 线程池的管理类
在线DEMO
http://www.voidcn.com/article/p-ounmxjds-tq.html
示例
1、Thread.xaml
[源码下载]
稳扎稳打Silverlight(25) - 2.0线程之Thread,Timer,BackgroundWorker,ThreadPool
作者:webabcd
介绍
Silverlight 2.0 使用Thread,ThreadPool来实现多线程开发
Thread - 用于线程的创建和控制的类
Timer - 用于以指定的时间间隔执行指定的方法的类
BackgroundWorker - 用于在单独的线程上运行操作
ThreadPool - 线程池的管理类
在线DEMO
http://www.voidcn.com/article/p-ounmxjds-tq.html
示例
1、Thread.xaml
<UserControl x:Class="Silverlight20.Thread.Thread"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left" Margin="5">
<TextBlock x:Name="txtMsg" />
</StackPanel>
</UserControl>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left" Margin="5">
<TextBlock x:Name="txtMsg" />
</StackPanel>
</UserControl>
Thread.xaml.cs
2、Timer.xaml
<UserControl x:Class="Silverlight20.Thread.Timer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left" Margin="5">
<TextBlock x:Name="txtMsg" />
</StackPanel>
</UserControl>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left" Margin="5">
<TextBlock x:Name="txtMsg" />
</StackPanel>
</UserControl>
Timer.xaml.cs
3、BackgroundWorker.xaml
<UserControl x:Class="Silverlight20.Thread.BackgroundWorker"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left" Margin="5">
<StackPanel Orientation="Horizontal" Margin="5">
<Button x:Name="btnStart" Content="开始" Margin="5" Click="btnStart_Click" />
<Button x:Name="btnCancel" Content="取消" Margin="5" Click="btnCancel_Click" />
</StackPanel>
<StackPanel Margin="5">
<TextBlock x:Name="txtProgress" Margin="5" />
<TextBlock x:Name="txtMsg" Margin="5" />
</StackPanel>
</StackPanel>
</UserControl>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left" Margin="5">
<StackPanel Orientation="Horizontal" Margin="5">
<Button x:Name="btnStart" Content="开始" Margin="5" Click="btnStart_Click" />
<Button x:Name="btnCancel" Content="取消" Margin="5" Click="btnCancel_Click" />
</StackPanel>
<StackPanel Margin="5">
<TextBlock x:Name="txtProgress" Margin="5" />
<TextBlock x:Name="txtMsg" Margin="5" />
</StackPanel>
</StackPanel>
</UserControl>
BackgroundWorker.xaml.cs
4、ThreadPool.xaml
<UserControl x:Class="Silverlight20.Thread.ThreadPool"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left" Margin="5">
<TextBlock x:Name="txtMsgQueueUserWorkItem" Text="click here" MouseLeftButtonDown="txtMsgQueueUserWorkItem_MouseLeftButtonDown" Margin="30" />
<TextBlock x:Name="txtRegisterWaitForSingleObject" Text="click here" MouseLeftButtonDown="txtRegisterWaitForSingleObject_MouseLeftButtonDown" Margin="30" />
</StackPanel>
</UserControl>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left" Margin="5">
<TextBlock x:Name="txtMsgQueueUserWorkItem" Text="click here" MouseLeftButtonDown="txtMsgQueueUserWorkItem_MouseLeftButtonDown" Margin="30" />
<TextBlock x:Name="txtRegisterWaitForSingleObject" Text="click here" MouseLeftButtonDown="txtRegisterWaitForSingleObject_MouseLeftButtonDown" Margin="30" />
</StackPanel>
</UserControl>
ThreadPool.xaml.cs
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。