Skip to content

Instantly share code, notes, and snippets.

class Program
{
static void Main(string[] args)
{
var data =
"No., Name, Price, Comment" + Environment.NewLine
+ "001, りんご, 98円, 青森産" + Environment.NewLine
+ "002, バナナ, 120円, \" とっても!\r\nお,い,し,い,よ!\"" + Environment.NewLine
+ "" + Environment.NewLine
+ "004, \"うまい棒\"\"めんたい\"\"\", 10円," + Environment.NewLine
@pierre3
pierre3 / ReadXsvAsync.md
Last active July 6, 2021 09:51
C# asyncでやってはいけないこと

ブログ記事非同期版読み取り用メソッドを定義する に対して頂いたご指摘に対するメモ。

  1. awaitせずにTaskをじかに返せる場合はasyncにせずにそのまま返した方が良い
  • メソッドを asyncにするだけでコストがかかる?
  1. Task.Runでラップしただけのような偽Asyncメソッドは基本避ける
  • 非同期処理メソッドを実装する際は、I/O依存の処理と、CPU依存の処理は分けて考えなければならない
  • ライブラリはI/O依存の処理のみを非同期メソッドとして提供すべきであり、CPU依存処理の非同期メソッドは提供すべきでない。
  • CPU依存の処理を非同期で行うか否かを決めるのはライブラリを使う側の権限
  • スレッド、スレッドプールはアプリケーション開発者側が管理すべきリソースなので、ライブラリ内部でTask.Run()等を使って(勝手に)消費したりしてはいけない。
@pierre3
pierre3 / asyncRead.cs
Last active August 29, 2015 13:59
C# メソッドをasyncにする、しないのパフォーマンス比較
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
@pierre3
pierre3 / MainWindow.xaml
Last active August 29, 2015 14:01
[WPF]CSVファイルを読み込んでDataGridに表示する
<Window x:Class="WpfApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:app="clr-namespace:WpfApp"
Title="MainWindow" Height="640" Width="800">
<Window.DataContext>
<app:CsvData/>
</Window.DataContext>
<Grid>
<Grid.RowDefinitions>
@pierre3
pierre3 / ModelShips.txt
Created May 17, 2014 06:41
船舶模型の一覧
No.,艦種,品名,税込価格,本体価格,メーカー
103,戦艦,山城 やましろ,1785,"1,700",A
104,戦艦,扶桑 ふそう,1785,"1,700",A
109,戦艦,金剛 こんごう,2625,"2,500",H
110,戦艦,比叡 ひえい,2625,"2,500",H
111,戦艦,榛名 はるな,2625,"2,500",H
112,戦艦,霧島 きりしま,2625,"2,500",H
113,戦艦,大和 やまと,2520,"2,400",T
114,戦艦,武蔵 むさし,2520,"2,400",T
115,戦艦,長門 ながと,2520,"2,400",A
@pierre3
pierre3 / RoslynSample.cs
Created July 5, 2014 00:57
C# Interactive interpreter-like console app
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using System;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Collections.Generic;
namespace ConsoleApplication1
{
@pierre3
pierre3 / MarkdownPreview.ps1
Last active August 29, 2015 14:06
お好みのテキストエディタにMarkdownプレビュー機能を追加するPowerShellスクリプト
# このスクリプト自身が格納されているディレクトリを取得
$Script:scriptDir = Split-Path $MyInvocation.MyCommand.Definition -Parent
<#
.Synopsis
Markdownテキストのプレビュー
.DESCRIPTION
Markdown形式で記述されたテキストファイルの内容をHTMLに変換し、ブラウザでプレビュー表示します。
.EXAMPLE
PS C:\> Start-Markdown .\markdownText.md
@pierre3
pierre3 / Iterator.cs
Last active August 29, 2015 14:06
Iterator class for debug
using System;
using System.Collections.Generic;
using System.Linq;
namespace IteratorTest
{
public static class IteratorHelper
{
//インスタンス生成を楽するためのショートカット
public static Iterator<T> CreateIterator<T>(params T[] source)
@pierre3
pierre3 / Linq.ps1
Last active August 29, 2015 14:07
[PowerShell] A enumeration cmdlet of delayed evaluation.
function Where-Block
{
[CmdletBinding()]
[OutputType([scriptblock])]
Param
(
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
Position=0)]
[PSObject]
@pierre3
pierre3 / Linq_verbose.ps1
Created October 1, 2014 15:05
Linq.ps1 with Write-Verbose
function Where-Block
{
[CmdletBinding()]
[OutputType([scriptblock])]
Param
(
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
Position=0)]
[PSObject]