Thread.sleep()方法在便携式类库 [英] Thread.Sleep() in a Portable Class Library

查看:209
本文介绍了Thread.sleep()方法在便携式类库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MSDN 的文档说 Thread.sleep代码()可以在移动的类库使用。编译器,否则说。什么是除了自旋环我的选择吗? Thread.CurrentThread.Join()也不存在



项目文件:

 <?XML版本=1.0编码=UTF-8>?; 
<项目ToolsVersion =4.0DefaultTargets =生成的xmlns =http://schemas.microsoft.com/developer/msbuild/2003>
<&的PropertyGroup GT;
<结构条件='$(配置)'==''>调试和LT; /结构>
<平台条件='$(平台)'==''>&值为anycpu LT; /平台和GT;
< ProjectGuid> {C46B138E-CC30-4397-B326-8DD019E3874B}< / ProjectGuid>
<输出类型>图书馆与LT; /输出类型>
< AppDesignerFolder>物业LT; / AppDesignerFolder>
< RootNamespace> x0xtest.AVR< / RootNamespace>
<&的AssemblyName GT; x0xtest.AVR< /的AssemblyName>
< TargetFrameworkVersion>&V4.0 LT; / TargetFrameworkVersion>
< TargetFrameworkProfile> Profile3< / TargetFrameworkProfile>
< FileAlignment> 512 LT; / FileAlignment>
< ProjectTypeGuids> {786C830F-07A1-408B-BD7F-6EE04809D6DB} {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}< / ProjectTypeGuids>
< /&的PropertyGroup GT;
<的PropertyGroup条件='$(配置)| $(平台)'=='调试|值为anycpu'>
< DebugSymbols>真< / DebugSymbols>
<&DEBUGTYPE GT;全< / DEBUGTYPE>
<优化>假LT; /优化>
< OutputPath> bin\Debug\< / OutputPath>
< DefineConstants> DEBUG,TRACE< / DefineConstants>
< ErrorReport>&提示LT; / ErrorReport>
将; WarningLevel→4&下; / WarningLevel>
< /&的PropertyGroup GT;
<的PropertyGroup条件='$(配置)| $(平台)'=='发布|值为anycpu'>
<&DEBUGTYPE GT; pdbonly< / DEBUGTYPE>
<优化>真< /优化>
< OutputPath> bin\Release\< / OutputPath>
< DefineConstants>跟踪和LT; / DefineConstants>
< ErrorReport>&提示LT; / ErrorReport>
将; WarningLevel→4&下; / WarningLevel>
< /&的PropertyGroup GT;
<&的ItemGroup GT;
<参考包括=系统/>
<参考包括=System.Core程序/>
< /&的ItemGroup GT;
<&的ItemGroup GT;
<编译包括=Attributes\AddressAttribute.cs/>
<编译包括=Attributes\RegAttribute.cs/>
<编译包括=Attributes\ROAttribute.cs/>
<编译包括=Attributes\RWAttribute.cs/>
<编译包括=Attributes\WOAttribute.cs/>
<编译包括=Devices\ATMega162.cs/>
<编译包括=Exceptions.cs/>
<编译包括=IntelHexFormat.cs/>
<编译包括=Properties\AssemblyInfo.cs/>
<编译包括=Proxy.cs/>
<编译包括=ProxyBase.cs/>
<编译包括=ProxyBase_UploadFirmware.cs/>
< /&的ItemGroup GT;
<&的ItemGroup GT;
< ProjectReference包括=.. \x0xtest.Comm\x0xtest.Comm.csproj>
<项目> {F78547AC-1CA1-4ADB-9FA8-3E7DEB682240}< /项目>
<名称>&x0xtest.Comm LT; /名称>
< / ProjectReference>
< /&的ItemGroup GT;
<导入项目=$(MSBuildExtensionsPath32)\Microsoft\Portable\ $(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets/>
<! - 要修改你的构建过程中,添加你的任务内低于目标之一,并取消它。
其它类似的扩展点的存在,看到Microsoft.Common.targets。
<目标名称=BeforeBuild>
< /目标>
<目标名称=AfterBuild>
< /目标>
- >
< /项目>


解决方案

这是便携式不幸的副作用。库通过减法变得高度便携,删除所有上的许多可能的目标只有一个不可用的部分。与主题类打乱,这是相当没有任何有用的成员。只是其中的5离开,内存屏障(),的CurrentCulture,CurrentThread,的CurrentUICulture和ManagedThreadId。



这看起来有点奇怪,做广告的目标的交集肯定支持更多。这可能涉及到的未做广告的。 Windows 8的即将推出的版本,这将使ARM内核的运行。否则,被称为WinRT的或地铁或.NET Metro风格应用的API,这取决于你用什么工具。 WinRT的严重削减了传统的Windows API,它System.Windows.Threading程序的命名空间是很空的。



这是要生成的的在做题时,Eeek,现在我该怎么办之类的。这里的可能的解决方法是燃烧了一个虚拟System.Threading.ManualResetEvent对象。它有一个WaitOne的(时间跨度)方法。



FWIW,我个人并不期待反对这个库编程。到目前为止,最令人震惊的珍闻是在Q&放大器;你所提供的链接的部分:




问:我想问什么了在
类System.Linq.Expressions.Expression的编译方法

答:它不支持在Windows Phone /的Xbox,所以只有当你的目标的Silverlight + .NET显示出来。




哎哟。便携,sportable。这需要炖一会儿。我同情DevDiv一般和大卫·基恩,特别是艰难的工作。


The MSDN docs say Thread.Sleep() can be used in a portable class library. The compiler says otherwise. What are my alternatives besides a spin-loop? Thread.CurrentThread.Join() doesn't exist either.

Project file:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{C46B138E-CC30-4397-B326-8DD019E3874B}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>x0xtest.AVR</RootNamespace>
    <AssemblyName>x0xtest.AVR</AssemblyName>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <TargetFrameworkProfile>Profile3</TargetFrameworkProfile>
    <FileAlignment>512</FileAlignment>
    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <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' ">
    <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" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Attributes\AddressAttribute.cs" />
    <Compile Include="Attributes\RegAttribute.cs" />
    <Compile Include="Attributes\ROAttribute.cs" />
    <Compile Include="Attributes\RWAttribute.cs" />
    <Compile Include="Attributes\WOAttribute.cs" />
    <Compile Include="Devices\ATMega162.cs" />
    <Compile Include="Exceptions.cs" />
    <Compile Include="IntelHexFormat.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
    <Compile Include="Proxy.cs" />
    <Compile Include="ProxyBase.cs" />
    <Compile Include="ProxyBase_UploadFirmware.cs" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\x0xtest.Comm\x0xtest.Comm.csproj">
      <Project>{F78547AC-1CA1-4ADB-9FA8-3E7DEB682240}</Project>
      <Name>x0xtest.Comm</Name>
    </ProjectReference>
  </ItemGroup>
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.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>

解决方案

This is the unfortunate side effect of "portable". A library becomes highly portable by subtraction, removing all the parts that are unavailable on just one of the many possible targets. That played havoc with the Thread class, it is quite devoid of any useful members. Just 5 of them left, MemoryBarrier(), CurrentCulture, CurrentThread, CurrentUICulture and ManagedThreadId.

This might look odd, the intersection of the advertized targets certainly support more. This is probably related to the un-advertized one. The upcoming version of Windows 8 that will run on ARM cores. Otherwise known as WinRT or Metro or the ".NET for Metro style apps" API, depending on what tools you use. WinRT severely cuts down on the traditional Windows API, its System.Windows.Threading namespace is pretty empty.

This is going to generated a ton of questions on SO, the "Eeek, now what do I do" kind. The possible workaround here is to burn up a dummy System.Threading.ManualResetEvent object. It has a WaitOne(TimeSpan) method.

Fwiw, I'm personally not looking forward to programming against this library. By far the most alarming tidbit is in the Q&A section of the link you provided:

Q: I wanted to ask what's up with the Compile method of the System.Linq.Expressions.Expression class.
A: It's not supported on Windows Phone/Xbox, so it only shows up when you target Silverlight + .NET.

Ouch. Portable, sportable. This needs to stew for a while. My sympathies to DevDiv in general and David Kean in particular, tough job.

这篇关于Thread.sleep()方法在便携式类库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆