Format:
Recent snippets for: bnaya
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);
15 Views
no comments
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);
13 Views
no comments
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); } }
28 Views
no comments
// compile in release mode bool stop = false; bool toggle = false; ThreadPool.QueueUserWorkItem(delegate { while (!stop) { toggle = !toggle; //Thread.MemoryBarrier(); }
16 Views
no comments
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;
21 Views
no comments
class Program { static void Main(string[] args) { bool isComplete = false; var t = Task.Factory.StartNew(() => { bool toggle = false; while (!isComplete) // read the cached value {
25 Views
no comments
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 [] {
37 Views
no comments
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));
31 Views
no comments
<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"/>
36 Views
no comments
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.
51 Views
no comments
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
54 Views
no comments
<!-- 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>
49 Views
no comments
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
102 Views
no comments
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; namespace TplKeepAlive { class Program
45 Views
no comments
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);
74 Views
no comments
layout="${longdate} ${logger} ${level} ${message} ${exception:format=Type,Message,StackTrace:separator=[br]}"
314 Views
no comments
if (Environment.UserInteractive) { service.Start(args); Console.WriteLine("Press any key to stop program"); Console.ReadKey(); service.Stop(); } else
95 Views
no comments
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);
148 Views
no comments
<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>
224 Views
no comments
using System; using System.Diagnostics; using System.Runtime.CompilerServices; namespace Tpl.Samples { public enum MyEnum { None = 0, A = 1,
335 Views
no comments
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search
