CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Format:
Recent snippets for: bnaya
C#
Func<int, int> invoker = ...;
 
var ar = invoker.BeginInvoke(42, ar =>
    {
        //We need to retrieve the delegate and the state:
        AsyncResult realAR = (AsyncResult)ar;
        int typedState = (int)ar.AsyncState;
        var invoker = (Func<int, int>)realAR.AsyncDelegate;
        //End the operation and print the result:
        int result = invoker.EndInvoke(ar);
by bnaya   January 14, 2012 @ 2:15pm
Tags: APM
15 Views
no comments
 
C#
var conn = new SqlConnection(CONN_STR);
var cmd = new SqlCommand("Select * from Employee", conn);
conn.Open();
cmd.BeginExecuteReader(ar =>
    {
        int affected = cmd.EndExecuteNonQuery(ar);
        cmd.Dispose();
        conn.Dispose();
    }, null);
by bnaya   January 14, 2012 @ 2:10pm
Tags: APM, DAL, ADO
13 Views
no comments
 
C#
public static class TypeEx
{
    public static string GetFriendlyName(this Type t)
    {
        using (var provider = new CSharpCodeProvider())
        {
            var typeRef = new CodeTypeReference(t);
            return provider.GetTypeOutput(typeRef);
        }
    }
by bnaya   January 10, 2012 @ 3:21am
28 Views
no comments
 
C#
// compile in release mode
bool stop = false;
bool toggle = false;
ThreadPool.QueueUserWorkItem(delegate
{
    while (!stop)
    {
        toggle = !toggle;
        //Thread.MemoryBarrier();
    }
by bnaya   January 04, 2012 @ 6:59am
16 Views
no comments
 
C#
private static WeakReference _weak;
const int ALLOCATION = 1024 * 100;
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
static void Main(string[] args)
{
    
    int count = 0;
    int times = 0;
    int i;
    string x = null;
by bnaya   January 02, 2012 @ 5:52am
21 Views
no comments
 
C#
class Program
{
    static void Main(string[] args)
    {
        bool isComplete = false;
        var t = Task.Factory.StartNew(() =>
        {
            bool toggle = false;
            while (!isComplete) // read the cached value
            {
by bnaya   December 14, 2011 @ 1:49am
Tags: Tpl, Parallel
25 Views
no comments
 
C#
static void Main(string[] args)
{
    var xs = Observable.Interval(TimeSpan.FromSeconds(0.5)).Publish().RefCount();
    var zs = xs.Buffer(xs.Sample(TimeSpan.FromSeconds(1.5)), x => xs.Skip(5).Take(1));
 
    zs.Subscribe(item => Console.WriteLine("{0} - {1}", item.First(), item.Last()));
    Console.ReadKey();
    Task<WebResponse>[] results = GetesourcesAsync(
        new []
        {
by bnaya   December 01, 2011 @ 9:21am
Tags: tpl, io
37 Views
no comments
 
C#
var xs = Observable.Interval(TimeSpan.FromSeconds(0.5)).Publish().RefCount();
var zs = xs.Buffer(xs.Sample(TimeSpan.FromSeconds(1.5)), x => xs.Skip(5).Take(1));
by bnaya   December 01, 2011 @ 9:19am
Tags: rx
31 Views
no comments
 
XML
<system.diagnostics>
      <sources>
        <source name="TraceSourceApp"
          switchName="sourceSwitch"
          switchType="System.Diagnostics.SourceSwitch">
          <listeners>
            <add name="console"
              type="System.Diagnostics.ConsoleTraceListener">
              <filter type="System.Diagnostics.EventTypeFilter"
                initializeData="Warning"/>
by bnaya   November 03, 2011 @ 12:25am
36 Views
no comments
 
C#
private static TraceSource mySource =
            new TraceSource("TraceSourceApp");
static void Main(string[] args)
{
    mySource.TraceEvent(TraceEventType.Error, 1, "Error message.");
 
    // Change the event type for which tracing occurs.
    // The console trace listener must be specified 
    // in the configuration file. First, save the original
    // settings from the configuration file.
by bnaya   November 03, 2011 @ 12:24am
51 Views
no comments
 
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reactive.Linq;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Threading.Tasks;
 
namespace Sela.Samples
by bnaya   October 23, 2011 @ 5:18am
Tags: rx, tpl
54 Views
no comments
 
XML
 <!-- find Microsoft.Common.targets under C:\Windows\Microsoft.NET\Framework\ -->
<Project DefaultTargets="Build" InitialTargets="_CheckForInvalidConfigurationAndPlatform"
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 
    <PropertyGroup>
        <UseVSHostingProcess>false</UseVSHostingProcess>
    </PropertyGroup>
 
    <!-- ... -->
</Project>
by bnaya   October 19, 2011 @ 1:10am
Tags: IDE, VS2010, VSHost
49 Views
no comments
 
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
 
namespace StaticMEF
{
    class Program
by bnaya   October 18, 2011 @ 8:50am
102 Views
no comments
 
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
 
namespace TplKeepAlive
{
    class Program
by bnaya   October 17, 2011 @ 7:19am
Tags: Tpl
45 Views
no comments
 
C#
public static class TaskCast
{
    public static explicit operator Task<T>(T sr);
    public static Task<T> operator +(T i1, T i2);
    public static Task<T> operator -(T i1, T i2);
    public static Task<T> operator *(T i1, T i2);
    public static Task<T> operator /(T i1, T i2);
    public static Task<T> operator %(T i1, T i2);
    public static Task<T> operator -(T i);
    public static Task<bool> operator ==(T i1, T i2);
by bnaya   March 23, 2011 @ 8:43am
Tags: Task, overload
74 Views
no comments
 
layout="${longdate} ${logger} ${level} ${message} ${exception:format=Type,Message,StackTrace:separator=[br]}"
by bnaya   March 17, 2011 @ 12:27am
Tags: NLog, Logging
314 Views
no comments
 
C#
if (Environment.UserInteractive)
{
    service.Start(args);
 
    Console.WriteLine("Press any key to stop program");
 
    Console.ReadKey();
    service.Stop();
}
else
by bnaya   March 08, 2011 @ 2:04am
95 Views
no comments
 
C#
const string PC_CATEGORY = "_Tmp";
const string PC_NAME = "_Tmp";
 
if (!PerformanceCounterCategory.Exists(PC_CATEGORY))
{
    CounterCreationDataCollection data = new CounterCreationDataCollection();
    CounterCreationData counter = new CounterCreationData(PC_NAME, "", PerformanceCounterType.NumberOfItems32);
    var pcCategory = PerformanceCounterCategory.Create(PC_CATEGORY, "", PerformanceCounterCategoryType.MultiInstance, data);
 
    data.Add(counter);
by bnaya   February 09, 2011 @ 12:45am
148 Views
no comments
 
XML
<Border BorderBrush="Black" BorderThickness="1.5" CornerRadius="12">
    <Border.Background>
        <ImageBrush>
            <ImageBrush.ImageSource>
                <BitmapImage UriSource="c:\temp\happy.jpg" />
            </ImageBrush.ImageSource>
        </ImageBrush>
    </Border.Background>
</Border>
by bnaya   February 08, 2011 @ 7:19am
224 Views
no comments
 
C#
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
 
namespace Tpl.Samples
{
    public enum MyEnum
    {
        None = 0,
        A = 1,
by bnaya   January 28, 2011 @ 5:51am
Tags: HasFlag, Enum
335 Views
no comments
 
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate