0 Comments
  •   Posted in: 
  • Task

When you have a simple for each loop in your code, sometimes it's possible to make the loop faster by using Tasks. The idea is to create a task for every item in the loop. You start the task when you go over it. After the loop finishes you will wait for all the tasks to finish and you are good to go..

This is an example of an optimized loop:

// Get the collection
var dataCollection = GetCollection();

// Create a list to keep track all tasks
var tasks = new List<Task>();

// Check all entries
foreach (var entry in data Collection)
{

     // Create a task and execute it immediately
     var t =Task.Run(() =>
     {

       // Do your thing here

      });

      // Add the task to keep track of it
      tasks.Add(t);

}

// Wait for all tasks to complete
Task.WaitAll(tasks.ToArray());

When you have a lot of items in your collection the benefits will increase.

0 Comments
When you are unit testing in ASP.NET MVC problems will occur when you don't use the FixtureSetup method. When you run 'all tests' and only the first test will pass, you will have to use a base class.

The error looks like:
'A route named 'XXXX' is already in the route collection. Route names must be unique.'

For example you can use this empty class and have your test class inheriting this base class:

using NUnit.Framework;

namespace MyNameSpace
{

    [TestFixture]
    public class BaseFixture
    {

          [TestFixtureSetUp]
          public void FixtureSetup()
          {

          }

          [TestFixtureTearDown]
          public void FixtureTearDown()
          {

          }

          [SetUp]
          public void SetupTest()
          {

          }

          [TearDown]
          public void TeardownTest()
          {

          }

     }

}

0 Comments
  •   Posted in: 
  • WPF
When you bind the DataContext of an UserControl XAML to the code part of the file, you can use this method:
DataContext="{BindingRelativeSource={RelativeSourceSelf}}"
If you want to bind to a property of another element, this is the way to go:

Width="{Binding ElementName=NameOfAnotherControl,Path=Width}"




0 Comments
How do we get this menu item on the toolbar.


And I want it Here:


Right click on the toolbar and click 'customize'. The customize window will open. Click on the 'Commands' tab and select the Toolbar 'Standard'.

Right now you click on 'Add command' and the following window will open.


Click on 'Edit' in the left pane, and Find 'Outline Collapse To Definitions' in the right pane.

Then hit 'Ok'


Move the command to the correct position and hit 'Close' and you're done.