Skip to content

Commit aabe2d6

Browse files
committed
update
1 parent 98ff2b3 commit aabe2d6

File tree

21 files changed

+928
-17
lines changed

21 files changed

+928
-17
lines changed

AsynchronousProgramming/App.xaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="AsynchronousProgramming.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:AsynchronousProgramming"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Windows;
7+
8+
namespace AsynchronousProgramming
9+
{
10+
/// <summary>
11+
/// App.xaml 的交互逻辑
12+
/// </summary>
13+
public partial class App : Application
14+
{
15+
}
16+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{69F5C12A-AE8A-4D21-B663-82F2983D933F}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<RootNamespace>AsynchronousProgramming</RootNamespace>
10+
<AssemblyName>AsynchronousProgramming</AssemblyName>
11+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<WarningLevel>4</WarningLevel>
15+
<Deterministic>true</Deterministic>
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<PlatformTarget>AnyCPU</PlatformTarget>
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>bin\Debug\</OutputPath>
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28+
<PlatformTarget>AnyCPU</PlatformTarget>
29+
<DebugType>pdbonly</DebugType>
30+
<Optimize>true</Optimize>
31+
<OutputPath>bin\Release\</OutputPath>
32+
<DefineConstants>TRACE</DefineConstants>
33+
<ErrorReport>prompt</ErrorReport>
34+
<WarningLevel>4</WarningLevel>
35+
</PropertyGroup>
36+
<ItemGroup>
37+
<Reference Include="System" />
38+
<Reference Include="System.Data" />
39+
<Reference Include="System.Xml" />
40+
<Reference Include="Microsoft.CSharp" />
41+
<Reference Include="System.Core" />
42+
<Reference Include="System.Xml.Linq" />
43+
<Reference Include="System.Data.DataSetExtensions" />
44+
<Reference Include="System.Xaml">
45+
<RequiredTargetFramework>4.0</RequiredTargetFramework>
46+
</Reference>
47+
<Reference Include="WindowsBase" />
48+
<Reference Include="PresentationCore" />
49+
<Reference Include="PresentationFramework" />
50+
</ItemGroup>
51+
<ItemGroup>
52+
<ApplicationDefinition Include="App.xaml">
53+
<Generator>MSBuild:Compile</Generator>
54+
<SubType>Designer</SubType>
55+
</ApplicationDefinition>
56+
<Page Include="MainWindow.xaml">
57+
<Generator>MSBuild:Compile</Generator>
58+
<SubType>Designer</SubType>
59+
</Page>
60+
<Compile Include="App.xaml.cs">
61+
<DependentUpon>App.xaml</DependentUpon>
62+
<SubType>Code</SubType>
63+
</Compile>
64+
<Compile Include="MainWindow.xaml.cs">
65+
<DependentUpon>MainWindow.xaml</DependentUpon>
66+
<SubType>Code</SubType>
67+
</Compile>
68+
</ItemGroup>
69+
<ItemGroup>
70+
<Compile Include="Properties\AssemblyInfo.cs">
71+
<SubType>Code</SubType>
72+
</Compile>
73+
<Compile Include="Properties\Resources.Designer.cs">
74+
<AutoGen>True</AutoGen>
75+
<DesignTime>True</DesignTime>
76+
<DependentUpon>Resources.resx</DependentUpon>
77+
</Compile>
78+
<Compile Include="Properties\Settings.Designer.cs">
79+
<AutoGen>True</AutoGen>
80+
<DependentUpon>Settings.settings</DependentUpon>
81+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
82+
</Compile>
83+
<EmbeddedResource Include="Properties\Resources.resx">
84+
<Generator>ResXFileCodeGenerator</Generator>
85+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
86+
</EmbeddedResource>
87+
<None Include="Properties\Settings.settings">
88+
<Generator>SettingsSingleFileGenerator</Generator>
89+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
90+
</None>
91+
</ItemGroup>
92+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
93+
</Project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Window x:Class="AsynchronousProgramming.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:AsynchronousProgramming"
7+
mc:Ignorable="d"
8+
Title="MainWindow" Height="450" Width="800">
9+
<DockPanel>
10+
<DockPanel DockPanel.Dock="Top" LastChildFill="True">
11+
<TextBlock DockPanel.Dock="Left">download address: </TextBlock>
12+
<Button DockPanel.Dock="Right" Click="Button_Click">download</Button>
13+
<TextBox Name="txbUrl"></TextBox>
14+
</DockPanel>
15+
<GroupBox Header="status: ">
16+
<TextBox Name="rtbState"></TextBox>
17+
</GroupBox>
18+
</DockPanel>
19+
</Window>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Net;
6+
using System.Text;
7+
using System.Threading;
8+
using System.Windows;
9+
using System.Windows.Controls;
10+
using System.Windows.Data;
11+
using System.Windows.Documents;
12+
using System.Windows.Input;
13+
using System.Windows.Media;
14+
using System.Windows.Media.Imaging;
15+
using System.Windows.Navigation;
16+
using System.Windows.Shapes;
17+
18+
namespace AsynchronousProgramming
19+
{
20+
/// <summary>
21+
/// MainWindow.xaml 的交互逻辑
22+
/// </summary>
23+
public partial class MainWindow : Window
24+
{
25+
string text = "http://download.microsoft.com/download/7/0/3/703455ee-a747-4cc8-bd3e-98a615c3aedb/dotNetFx35setup.exe";
26+
public MainWindow()
27+
{
28+
InitializeComponent();
29+
txbUrl.Text = text;
30+
}
31+
32+
private void Button_Click(object sender, RoutedEventArgs e)
33+
{
34+
rtbState.AppendText("downloading......\n");
35+
if (string.IsNullOrWhiteSpace(txbUrl.Text))
36+
{
37+
MessageBox.Show("please input download address");
38+
return;
39+
}
40+
DownloadFileSync(txbUrl.Text.Trim());
41+
}
42+
43+
private void DownloadFileSync(string url)
44+
{
45+
int buffSize = 2048;
46+
byte[] bufferRead = new byte[buffSize];
47+
string savePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\dotNetFx 35setup.exe";
48+
FileStream fileStream = null;
49+
HttpWebResponse myWebResponse = null;
50+
if (File.Exists(savePath))
51+
{
52+
File.Delete(savePath);
53+
}
54+
55+
fileStream = new FileStream(savePath, FileMode.OpenOrCreate);
56+
try
57+
{
58+
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
59+
if (myHttpWebRequest != null)
60+
{
61+
myWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
62+
Stream responseStream = myWebResponse.GetResponseStream();
63+
int readSize = responseStream.Read(bufferRead, 0, buffSize);
64+
while (readSize > 0)
65+
{
66+
rtbState.AppendText($"get {readSize} bytes\n");
67+
fileStream.Write(bufferRead, 0, readSize);
68+
readSize = responseStream.Read(bufferRead, 0, buffSize);
69+
}
70+
rtbState.AppendText($"finish download, the size of file is {fileStream.Length}, and the path of file is {savePath}\n");
71+
}
72+
}
73+
catch(Exception e)
74+
{
75+
rtbState.AppendText($"error: {e.Message}\n");
76+
}
77+
finally
78+
{
79+
if (myWebResponse!=null)
80+
{
81+
myWebResponse.Close();
82+
}
83+
if (fileStream!=null)
84+
{
85+
fileStream.Close();
86+
}
87+
}
88+
}
89+
}
90+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.Reflection;
2+
using System.Resources;
3+
using System.Runtime.CompilerServices;
4+
using System.Runtime.InteropServices;
5+
using System.Windows;
6+
7+
// 有关程序集的一般信息由以下
8+
// 控制。更改这些特性值可修改
9+
// 与程序集关联的信息。
10+
[assembly: AssemblyTitle("AsynchronousProgramming")]
11+
[assembly: AssemblyDescription("")]
12+
[assembly: AssemblyConfiguration("")]
13+
[assembly: AssemblyCompany("")]
14+
[assembly: AssemblyProduct("AsynchronousProgramming")]
15+
[assembly: AssemblyCopyright("Copyright © 2021")]
16+
[assembly: AssemblyTrademark("")]
17+
[assembly: AssemblyCulture("")]
18+
19+
// 将 ComVisible 设置为 false 会使此程序集中的类型
20+
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
21+
//请将此类型的 ComVisible 特性设置为 true。
22+
[assembly: ComVisible(false)]
23+
24+
//若要开始生成可本地化的应用程序,请设置
25+
//.csproj 文件中的 <UICulture>CultureYouAreCodingWith</UICulture>
26+
//例如,如果您在源文件中使用的是美国英语,
27+
//使用的是美国英语,请将 <UICulture> 设置为 en-US。 然后取消
28+
//对以下 NeutralResourceLanguage 特性的注释。 更新
29+
//以下行中的“en-US”以匹配项目文件中的 UICulture 设置。
30+
31+
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32+
33+
34+
[assembly: ThemeInfo(
35+
ResourceDictionaryLocation.None, //主题特定资源词典所处位置
36+
//(未在页面中找到资源时使用,
37+
//或应用程序资源字典中找到时使用)
38+
ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置
39+
//(未在页面中找到资源时使用,
40+
//、应用程序或任何主题专用资源字典中找到时使用)
41+
)]
42+
43+
44+
// 程序集的版本信息由下列四个值组成:
45+
//
46+
// 主版本
47+
// 次版本
48+
// 生成号
49+
// 修订号
50+
//
51+
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
52+
// 方法是按如下所示使用“*”: :
53+
// [assembly: AssemblyVersion("1.0.*")]
54+
[assembly: AssemblyVersion("1.0.0.0")]
55+
[assembly: AssemblyFileVersion("1.0.0.0")]

AsynchronousProgramming/Properties/Resources.Designer.cs

Lines changed: 71 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)