Skip to content

Instantly share code, notes, and snippets.

View peteraritchie's full-sized avatar
😖

Peter Ritchie peteraritchie

😖
View GitHub Profile
@peteraritchie
peteraritchie / test.cs
Created August 22, 2011 03:17
code to create an Action<T> that will call a method that takes an object.
sbc.Subscribe(subs =>
{
Type type = GetRuntimeType(); // e.g. reflecting IHandle type...
//get pointer to generic method of specific type parameter
var methodInfo = subs.GetType().GetMethod("Handler", BindingFlags.Instance | BindingFlags.Public);
methodInfo = methodInfo.MakeGenericMethod(type);
// set up an action compatible with our method
@peteraritchie
peteraritchie / stuff.cs
Created January 18, 2012 15:15
sample code
private T HandleItemCacheRetrieval<T>(string cacheKey, object cacheLock, Func<T> nonCachedMethod)
{
T retVal = default(T);
try
{
retVal = (T) Get(cacheKey);
}
catch (InvalidCastException ex) //it didn’t parse properly
{
LoggerManager.Error(ex);
@peteraritchie
peteraritchie / feb-8-2012.cs
Created February 9, 2012 16:38
fun with WCF
var client = new ServiceReference1.Service1Client();
var retried = 0;
bool succeeded = false;
while (!succeeded)
{
if(retried > 42) throw new InvalidOperationException("Math is too hard.");
try
{
var result = client.GetData(42);
succeeded = true;
@peteraritchie
peteraritchie / gist:1885565
Created February 22, 2012 15:32
beginendtpl
var task = Task.Factory.FromAsync(networkStream.BeginWrite,
networkStream.EndWrite,
data, 0, data.Length,
networkStream);
Task<Task<int>> task2 = task.ContinueWith(_ => Task<int>.Factory.FromAsync(
networkStream.BeginRead,
networkStream.EndRead,
incomingData, 0,
incomingData.Length,
networkStream));
@peteraritchie
peteraritchie / gist:1885584
Created February 22, 2012 15:37
beginendwotpl
NetworkStream networkStream = tcpClient.GetStream();
networkStream.BeginWrite(data, 0, data.Length,
OnWriteCompleted, networkStream);
private static void OnWriteCompleted(IAsyncResult ar)
{
NetworkStream myNetworkStream =
(NetworkStream)ar.AsyncState;
myNetworkStream.EndWrite(ar);
@peteraritchie
peteraritchie / gist:1885697
Created February 22, 2012 16:02
beginwithlambda
networkStream.BeginWrite(data, 0, data.Length,
ar =>
{
NetworkStream myNetworkStream =
(NetworkStream) ar.AsyncState;
myNetworkStream.EndWrite(ar);
}, networkStream);
@peteraritchie
peteraritchie / gist:1885798
Created February 22, 2012 16:08
supersimpletpl
Task.Factory.StartNew(() => Console.Write("started working..."))
.ContinueWith(_ => Console.WriteLine("doing something else..."))
.ContinueWith(_ => Console.WriteLine("done!"));
error CS0583: Internal Compiler Error (0xc0000005 at address 000007F6B95A94B2):
likely culprit is 'TRANSFORM'.
An internal error has occurred in the compiler. To work around this
problem, try simplifying or changing the program near the locations
listed below. Locations at the top of the list are closer to the point
at which the internal error occurred. Errors such as this can be
reported to Microsoft by using the /errorreport option.
snippet.txt(7,27): error CS0584: Internal Compiler Error: stage 'TRANSFORM'
@peteraritchie
peteraritchie / error.txt
Created March 10, 2012 18:27
.net profile error
The referenced assembly "X" could not be resolved because it has a dependency on "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project.
@peteraritchie
peteraritchie / error2.txt
Created March 10, 2012 18:30
gist description
Attempted re-targeting of the project has been canceled. To be able to target your test project to .NET Framework 3.5, you must use the steps documented at the following Microsoft Web site: http://go.microsoft.com/fwlink/?LinkId=201405.