22

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>
4

5 に答える 5

25

これは「ポータブル」の不幸な副作用です。ライブラリは、減算によって移植性が高くなり、多くの可能なターゲットの1つだけで使用できないすべてのパーツが削除されます。それはThreadクラスで大混乱を引き起こしました、それはどんな有用なメンバーも全く欠いています。残りの5つは、MemoryBarrier()、CurrentCulture、CurrentThread、CurrentUICulture、ManagedThreadIdです。

これは奇妙に見えるかもしれません、宣伝されたターゲットの交差点は確かにより多くをサポートします。これはおそらく、広告されていないものに関連しています。ARMコアで実行されるWindows8の次期バージョン。使用するツールに応じて、WinRTまたはMetro、または「.NETforMetroスタイルアプリ」APIとも呼ばれます。WinRTは、従来のWindows APIを大幅に削減し、そのSystem.Windows.Threading名前空間はかなり空になっています。

これにより、SOに関する大量の質問が生成されます。これは、「Eeek、nowdoIdoI」の種類ですここで考えられる回避策は、ダミーのSystem.Threading.ManualResetEventオブジェクトを焼き払うことです。WaitOne(TimeSpan)メソッドがあります。

Fwiw、私は個人的にこのライブラリに対するプログラミングを楽しみにしていません。最も憂慮すべき一口は、あなたが提供したリンクのQ&Aセクションにあります。

Q:System.Linq.Expressions.ExpressionクラスのCompileメソッドはどうなっているのか尋ねたいと思いました。
A:Windows Phone / Xboxではサポートされていないため、Silverlight+.NETをターゲットにしている場合にのみ表示されます。

痛い。ポータブル、スポーティ。これはしばらく煮込む必要があります。DevDiv全般、特にDavid Keanに同情し、大変な仕事をしました。

于 2012-02-12T23:06:08.390 に答える
19

(私はマイクロソフトのポータブルライブラリプロジェクトを「所有」しています)

残念ながら、これは、Metroアプリで実行および参照できるようにするために行った、ポータブルライブラリプロジェクトの表面積に対する最近の変更でした。Metroスタイルアプリ、Visual Studio 11、およびWindows 8の新しい機能の1つは、アプリが独自のスレッドを作成および制御する必要をなくすことです(これを正しく行うのは困難です)。代わりに、言語(つまり、 async/ await)とフレームワーク機能(Task)を使用して、バックグラウンドで実行する必要のある操作を実行および同期するという考え方です。

代わりに何を使用するか(たとえばManualResetEvent、、Task.Delay)は、シナリオとターゲットとするプラットフォームによって完全に異なります。あなたがしていることを説明できますか?

于 2012-02-19T04:12:46.883 に答える
18
System.Threading.Tasks.Task.Delay(ms).Wait();

のドロップイン代替品として機能します

System.Threading.Thread.Sleep(ms);

これは、レガシーコードベースを移植するときに正常に機能します。

于 2015-07-24T13:10:25.453 に答える
5

タイムアウトしてhttp://msdn.microsoft.com/en-us/library/system.threading.manualresetevent.aspxで待機してみてください。

于 2012-02-12T23:04:15.930 に答える
4

Task.Delayで使用できますSystem.Threading.Tasks

于 2015-04-05T06:05:51.893 に答える