Skip to content

Instantly share code, notes, and snippets.

View peace2048's full-sized avatar

naoki ochiai peace2048

View GitHub Profile
@peace2048
peace2048 / NewDesktop.cpp
Created March 4, 2015 02:47
デスクトップを作成した上でアプリケーションを起動する
#include "stdafx.h"
#include <Windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR commandLine[MAX_PATH] = { 0 };
HDESK hOldDesk, hInputDesk, hNewDesk;
STARTUPINFO si;
PROCESS_INFORMATION pi;
BOOL success;
@peace2048
peace2048 / DbLoggingWrapper.vb
Last active August 29, 2015 14:19
IDbCommand にログ出力を追加
Imports System.Data
Imports System.Runtime.CompilerServices
Imports Common.Logging
Public Class DbLoggingWrapper
Private Shared _logger As ILog
Public Shared Property Logger As ILog
Get
If _logger Is Nothing Then
@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))]
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))
public static Class EnumerableEx
{
}
@peace2048
peace2048 / vs2015_vb_cs_futre.md
Created August 31, 2015 01:34
VS2015 での VB, C# の新機能

VB, C# の新機能

TaskCompletionSource でハマる

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

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

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

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();

サンプルデータの作成

<Extension>
Public Iterator Function Repeat(Of T)(element As T) As IEnumerable(Of T)
	While True
		Yield element
	End While
End Function
@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()