Skip to content

Instantly share code, notes, and snippets.

View peace2048's full-sized avatar

naoki ochiai peace2048

View GitHub Profile
ctx.Database.Log = message => Console.WriteLine(message);
<Query Kind="Statements">
<Reference>&lt;RuntimeDirectory&gt;\System.Windows.Forms.dll</Reference>
<NuGetReference>OxyPlot.WindowsForms</NuGetReference>
<Namespace>OxyPlot</Namespace>
<Namespace>OxyPlot.Axes</Namespace>
<Namespace>OxyPlot.Series</Namespace>
</Query>
var pm = new PlotModel
{
@peace2048
peace2048 / Form1.vb
Last active March 2, 2016 06:41
forms_databinding.md
Imports System.ComponentModel
Public Class Form1
Private _model As New Model()
Public Sub New()
InitializeComponent()

サンプルデータの作成

<Extension>
Public Iterator Function Repeat(Of T)(element As T) As IEnumerable(Of T)
	While True
		Yield element
	End While
End Function
void Main()
{
var connection = ConnectionMultiplexer.Connect("192.168.5.40");
var sx1 = connection.ObservableSubscription("pa");
using (sx1.Subscribe(_ => Console.WriteLine(_))) Console.ReadLine();
var sx2 = connection.ObservableList("qa", TimeSpan.FromSeconds(5));
using (sx2.Subscribe(_ => Console.WriteLine(_))) Console.ReadLine();

TaskCompletionSource でハマる

別に TaskCompletionSource でハマったわけではないですが、TaskCompletionSource で作成したタスクを Async/Await で待ったときにハマってしまった。

元々、OPC Automation で非同期入出力が、コマンドに対しイベントで完了を通知していますので、TaskCompletionSource を使って Task にする説明を考えていました。

最初に、チョロット書こうとしていたことを事実を捻じ曲げて説明します。(本当は引数等が違います。) OPC Automation では、AsyncRead に対し完了を AsyncReadComplete イベントで通知し、操作のキャンセルも AsyncCancel に対し AsyncCancelComplete で完了を通知しています。

@peace2048
peace2048 / vs2015_vb_cs_futre.md
Created August 31, 2015 01:34
VS2015 での VB, C# の新機能

VB, C# の新機能

public static Class EnumerableEx
{
}
open System.Net
open System.Net.Sockets
type IpMessenger (port: int) =
let client = new UdpClient(port)
let random = new Random(Environment.TickCount)
let nextId = fun () -> random.Next(0, 1000)
let sendBuffer (address: IPAddress, message: Byte[]) =
client.Send(message, message.Length, new IPEndPoint(address, 2425))
@peace2048
peace2048 / DropDownButton.cs
Created May 19, 2015 08:51
WPF DropDownBox
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
namespace WpfApplication1
{
[TemplatePart(Name = PART_ContentPresenter, Type = typeof(ContentPresenter))]
[TemplatePart(Name = PART_DropDownButton, Type = typeof(ToggleButton))]