Skip to content

Instantly share code, notes, and snippets.

@Immerseit
Immerseit / ThreadedProcessStarter.cs
Created June 27, 2011 08:42
Simple Process Start & Kill By Threads
static void Main()
{
//Dictionary if there happen to be different software to run, per row.
Dictionary<string,string> actions = new Dictionary<string,string>();
actions.Add("http://www.site1.com", @"C:\Program Files\Mozilla Firefox\firefox.exe");
actions.Add("http://site2.com", @"C:\Program Files\Mozilla Firefox\firefox.exe");
actions.Add("http://site3.org/", @"C:\Program Files\Mozilla Firefox\firefox.exe");
foreach (var row in actions)
@Immerseit
Immerseit / ServiceQueue.cs
Created June 30, 2011 21:18
Not complete ServiceQueue problem that need some help,
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// My problem description. You are welcome to comment/fork your own tried/functional versions of this.
// Appearently I have successed the queue on all needed situations. Except a trivial one, the ervice aren't really dequeue.
// The two methods below is two services that are ranned simultaneous within same application (a Windows Service).
//
// 1# As I can see, the line 'if (queue.TryDequeue(..))' never get looped/waked-up..
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// The object that will Enqueue, put object into Queue (can be put into a console application)
@Immerseit
Immerseit / EnumClassSample.cs
Created September 16, 2011 09:51
Combine Enum and Class for Extended functionality
// The idea is to collect this kind of parsing nearest possible to the enum itself
// Why? Because the enum is the reason to the Method and are easy to find and modify
// Also it's natural to extend with other kind of parsing. Just insert more methods.
// The main drawback, is that I have to state the enum more explicit (i.e. Something.TypeOf)
// Also the code design appears no standard and would apply if the enum was for internal use in the class.
// So, the question
// How would you do this more nice? I tried abstract, base inheritance, partial. None of them apply.
// This is a shortened down and renamed sample of a code that should be better coded.
@Immerseit
Immerseit / FillGapsInArray.cs
Created September 16, 2011 15:33
Find and fill gaps in a DateTime array
/// <summary>
/// Fill gaps in referred List (based on date).
/// Dynamic due to a Period which add ticks to the DateTime instead of a static "Days" or dito.
/// </summary>
public static void FillGapsInArray(ref List<ObjectWithDateField> range, Period period)
{
long ticks = PeriodParse.GetTicks(period);
List<ObjectWithDateField> gaps = new List<ObjectWithDateField>();
@Immerseit
Immerseit / Object2Xml.cs
Created September 21, 2011 21:13
A Readable way to create a simple C# Class and Serialize to XML
namespace Object2Serializer
{
/// 2011-09-21 XmlSerialization
/// This class content (definition) was created due to a third-partys serialized stream of text (xml alike)
/// With data from i.e. a database, the lists Graph and Set should be populated. And then
/// .GenerateXmlText() will do the whole work! Easy extendable with GenerateJson and so on.
/// As a little side note. There are just three lines in the Serialize-method to make a xml-standard.
public static partial class Program
{
@Immerseit
Immerseit / OneClickButton.cs
Created April 23, 2012 07:04
Do button blick as Callback
public class OneClickButton : Button
{
protected override void OnClick(EventArgs e)
{
this.Enabled = false;
PerformAsync(CallBack);
base.OnClick(e);
}
void CallBack()
@Immerseit
Immerseit / BlockingCollection
Created April 25, 2012 09:31
Sample of BlockingCollection in .NET 4
///
/// Function in a method that put items to queue
///
while (!queue.QueueManager.TryAdd(ResultOfValidation, new Random().Next(20)))
Console.WriteLine("Some text output logging because of error.");
///
/// Queue Class
///
public class Queue
@Immerseit
Immerseit / DoNotFloat
Created August 22, 2012 14:28
Unexpected (maybe?) result hided behind bad use of "float"
void Main()
{
string item = "134217963";
ValueFlags vf = new ValueFlags();
float _value;
if (float.TryParse(item, out _value))
{
vf.Value = _value.ToString();
}
@Immerseit
Immerseit / PageFlowSplitter
Created September 5, 2012 14:46
PageFlowSplitter
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;
namespace PageflowBreaker
{
[TestClass]
public class UnitTest1
{
@Immerseit
Immerseit / AssertThrowHelper.cs
Created October 4, 2012 06:47
Throw Exception Helper for Asserts
// var myTest = new Namespace.TheService();
// var ex = ExceptionFactory.Throws<InvalidOperationException>(() =>
// myTest.Result = myTest.Execute() );
// Assert.AreEqual(myTest.Result, null);
// Assert.AreEqual(ex.AnyProp, "ExpectedData");
public static class ExceptionFactory
{
public static T Throws<T>(Action action) where T : Exception
{