【发布时间】:2012-02-12 19:26:06
【问题描述】:
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>
【问题讨论】:
-
编译器是怎么说的?一个简短但完整的示例(包括错误消息)会有所帮助。
-
问题可能出在您项目的设置/配置中,但您会对 lib 的用户造成伤害。所以不要解决这个问题,而是摆脱 Sleep()。
-
在这里同意@HenkHolterman(我认为)。您想要解决的什么问题让您认为
Thread.Sleep是正确的解决方案? -
@JonSkeet “System.Threading.Thread 不包含‘睡眠’的定义”它也不属于智能感知。 C# 代码无关紧要。项目和开发机器的设置/配置更难传达。我将使用项目文件更新我的 Q。基本上,它是一个针对 .NET 4 和 Silverlight 4 的 PCL。我昨天通过链接here 下载并安装了便携式库工具。 VS 2010 是带有所有 Microsoft 更新的 SP1。
-
@Damien_The_Unbeliever 我正在通过 RS232 与设备通信,我需要暂停一下。