This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class="WpfApplication4.MainWindow" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
mc:Ignorable="d" DataContext="{Binding RelativeSource={RelativeSource Self}}" | |
Title="MainWindow" Height="350" Width="525"> | |
<StackPanel> | |
<ComboBox ItemsSource="{Binding Items}" SelectedValue="{Binding Selected}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
private static Action<string> _saved; | |
static void Main(string[] args) | |
{ | |
M(); | |
M(); | |
Console.WriteLine("Back in Main()..."); | |
Console.ReadKey(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Runtime.CompilerServices; | |
using System.Windows; | |
using System.Windows.Data; | |
namespace Utilities | |
{ | |
public static class DependencyPropertyExtensions | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Executes passed task (probably result of async method call) on a Dispatcher as | |
/// synchronous one, but without Wait() and risk of deadlock, using new dispatcher frame | |
/// that is finished as a continuation of passed task. | |
/// | |
/// You should still await the task returned back if you want correct exception propagation. | |
/// | |
/// Note that you can execute this method only if you're in a WPF dispatcher's context, | |
/// otherwise it will throw an exception. | |
/// </summary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = new StrongBox<object>(new object()); | |
var w = new WeakReference(a.Value); | |
a.Value = null; | |
GC.Collect(); | |
GC.WaitForPendingFinalizers(); | |
GC.Collect(); | |
Console.WriteLine(w.IsAlive ? "Alive" : "Dead"); | |
Console.ReadLine(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Represents AutomationPeer for certain data item. As data item is not control or even FrameworkElement, | |
/// it delegates most of its properties to the wrapping container item (generated by ItemContainerGenerator | |
/// as part of UI virtualization process). | |
/// </summary> | |
/// <remarks> | |
/// Most of the time automation client will work with this peer. It saves data item and not container because | |
/// container could be virtualized and then recycled. With this peer, client is safe from such details, as for | |
/// each operation we will get the container that currently wraps requested data item first and ask it for | |
/// corresponding property. Hence client does not need to worry about UI virtualization implementation details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Char | |
import Control.Monad | |
newtype Parser a = P (String -> [(a, String)]) | |
parse :: Parser a -> String -> [(a, String)] | |
parse (P p) str = p str | |
instance Monad Parser where | |
return v = P (\inp -> [(v, inp)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.Reflection; | |
namespace CommonTypes.Utilities.WeakDelegates | |
{ | |
public delegate void UnregisterCallback<TEventArgs>(EventHandler<TEventArgs> eventHandler) | |
where TEventArgs : EventArgs; | |
public static class EventHandlerUtils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
try | |
{ | |
int i = 0; | |
while (true) | |
{ | |
Console.WriteLine("Line {0}", i++); |