MSDN文档说Thread.Sleep()
可以在可移植类库中使用。编译器另有说明。除了自旋环外,我还有哪些选择? Thread.CurrentThread.Join()
也不存在。
项目文件:
<?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>
最佳答案
这是“便携式”的不幸副作用。通过减法,库变得高度可移植,删除了许多可能的目标之一中不可用的所有部分。这对Thread类造成了严重破坏,它完全没有任何有用的成员。仅剩5个了,分别是MemoryBarrier(),CurrentCulture,CurrentThread,CurrentUICulture和ManagedThreadId。
这可能看起来很奇怪,广告目标的交叉点当然支持更多。这可能与未经广告的广告有关。 Windows 8即将发布的版本将在ARM内核上运行。取决于您使用的工具,也称为WinRT或Metro或“.NET for Metro风格的应用程序” API。 WinRT严重削减了传统的Windows API,它的System.Windows.Threading命名空间非常空。
这将对SO产生大量问题,例如“Eeek,现在我该怎么办”。此处可能的解决方法是烧毁一个虚拟的System.Threading.ManualResetEvent对象。它具有WaitOne(TimeSpan)方法。
Fwiw,我个人不希望针对该库进行编程。到目前为止,最令人担忧的花絮是在您提供的链接的“问答”部分中:
哎哟。便携,运动。这需要炖一会儿。我对DevDiv尤其是David Kean的同情是艰巨的工作。
关于c# - 便携式类库中的Thread.Sleep(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9251917/