Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinkerc committed May 16, 2015
1 parent 7c33e08 commit 1a0b35f
Show file tree
Hide file tree
Showing 2,029 changed files with 1,676,642 additions and 0 deletions.
22 changes: 22 additions & 0 deletions AsyncConsoleApplication1/AsyncConsoleApplication1.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AsyncConsoleApplication1", "AsyncConsoleApplication1\AsyncConsoleApplication1.csproj", "{3068C2E0-E46A-4B0D-BF1E-4A8FC7A3207F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3068C2E0-E46A-4B0D-BF1E-4A8FC7A3207F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3068C2E0-E46A-4B0D-BF1E-4A8FC7A3207F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3068C2E0-E46A-4B0D-BF1E-4A8FC7A3207F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3068C2E0-E46A-4B0D-BF1E-4A8FC7A3207F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file not shown.
6 changes: 6 additions & 0 deletions AsyncConsoleApplication1/AsyncConsoleApplication1/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{3068C2E0-E46A-4B0D-BF1E-4A8FC7A3207F}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AsyncConsoleApplication1</RootNamespace>
<AssemblyName>AsyncConsoleApplication1</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
79 changes: 79 additions & 0 deletions AsyncConsoleApplication1/AsyncConsoleApplication1/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace AsyncConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
/* ConsoleAsync1();
stopwatch.Stop();
Console.WriteLine("同步方法用时:" + stopwatch.ElapsedMilliseconds);
stopwatch.Reset();
stopwatch.Start();*/
Console.WriteLine("我是主线程:Thread Id {0}", Thread.CurrentThread.ManagedThreadId);

Console.WriteLine("异步方法100000000");
ConsoleAsync(100000000);

Console.WriteLine("执行另外一个方法");
ConsoleAsync(3000);

//Console.WriteLine("同步方法100000000:" + Calculate(100000000));
stopwatch.Stop();
Console.WriteLine("异步方法用时:" + stopwatch.ElapsedMilliseconds);

Console.Read();
}

private static async void ConsoleAsync(int arraySize)
{
Console.WriteLine("我是ConsoleAsync线程:Thread Id {0}", Thread.CurrentThread.ManagedThreadId);
Console.WriteLine(arraySize + "异步方法开始");
Console.WriteLine("Result:" + await SumAsync(arraySize));
Console.WriteLine(arraySize + "异步方法结束");
}
private static async Task<string> SumAsync(int arraySize)
{
//HttpClient client = new HttpClient();
//Task<string> getStringTask = client.GetStringAsync("http://www.baidu.com");
//Console.WriteLine(DateTime.Now.Millisecond + " 异步 " + (await getStringTask).Length);


Task<string> getStringTask = new Task<string>(() => Calculate(arraySize));
getStringTask.Start();
//getStringTask.Wait();

return await getStringTask;
}

private static string Calculate(int arraySize)
{
// Thread.Sleep(3000);
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
var data = new int[arraySize];
var r = new Random();
for (int i = 0; i < arraySize; i++)
{
data[i] = r.Next(40);
}

var sum = data.AsParallel().Where(d => d < 20).Sum();

Console.WriteLine("我是Calculate线程:Thread Id {0}", Thread.CurrentThread.ManagedThreadId);
Console.WriteLine("用时:" + stopwatch.ElapsedMilliseconds);

return arraySize + "总和:" + sum;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// 有关程序集的常规信息通过以下
// 特性集控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("AsyncConsoleApplication1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AsyncConsoleApplication1")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// 将 ComVisible 设置为 false 使此程序集中的类型
// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
// 则将该类型上的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]

// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("292f413c-267c-4860-b757-666e36fdf281")]

// 程序集的版本信息由下面四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
</configuration>
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
D:\TestProject\AsyncConsoleApplication1\AsyncConsoleApplication1\bin\Debug\AsyncConsoleApplication1.exe.config
D:\TestProject\AsyncConsoleApplication1\AsyncConsoleApplication1\bin\Debug\AsyncConsoleApplication1.exe
D:\TestProject\AsyncConsoleApplication1\AsyncConsoleApplication1\bin\Debug\AsyncConsoleApplication1.pdb
D:\TestProject\AsyncConsoleApplication1\AsyncConsoleApplication1\obj\Debug\AsyncConsoleApplication1.csprojResolveAssemblyReference.cache
D:\TestProject\AsyncConsoleApplication1\AsyncConsoleApplication1\obj\Debug\AsyncConsoleApplication1.exe
D:\TestProject\AsyncConsoleApplication1\AsyncConsoleApplication1\obj\Debug\AsyncConsoleApplication1.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 1a0b35f

Please sign in to comment.