ALL IN SIGHT

Home of the AlmostImplementedException

How to get responsive UIs with BackgroundWorkers

Since WPF and especially Windows 8 its obligatory to build responsive UIs. This means, the UI is always responding to an user-request even if a long taking request is made.
An easy way to achieve this is a background worker, which is nothing more then an extra thread which can work with the UI-Thread. If you don’t know why that’s so important search for it, or wait for a tutorial :D (little hint: only ONE process can update the user interface!).

To work with ...

, , , ,

How to use Method Parameters ref, out, params

Today I want to show you, how we can use method parameters to solve specific problems.
At first, we’ll look at ref and out. Normaly a parameter is used to give a value into a function or method. But sometimes we need a different behavior.
If we want to return multiple values the out-keyword is our best friend. When you want to use out, you have to write the out-keyword ahead of the parameter and as well in the method-call.
This little example show us how to do ...

, , ,

Implementation of a string reverse Extension Method

This is a follow-up of Introducing Extension Methods

This method is an extension of the string-class. It reverts a string in a very efficient way and it is widely used around the world.
Faster methodes use either unsafe code or only work fast on very short strings.

, , ,

How to save multiple numbers into one byte

Sometimes you have to work with alot of numbers and want to save them in a file. Especially when you want to save alot of small numbers, it is inefficient to use a whole byte, or worse an int.

When i started to write a program to search a specific pattern of moves played in a database of Go-Game-Records, i came across this problem.
But at first, let us have a deeper look into bits and bytes. Most of you know 8bits are a byte and a byte is ...

,

An easy way to measure a functions performance

At some point in the development of a function or application we ask our self: “Is this the best way to do it”. This is the moment for StopWatch to step forward and help us out.

Normaly we would add StopWatch to the method we want to measure and remove the code afterwards. But that’s alot of work, especialy if want to measure several methods or continuously in a products lifecycle.

But, as promised, there is an easy way to do it. The answer to our prayers is the Action-Delegate. ...

Compile code at runtime

Sometimes it is necessary to compile code explicitly at runtime. For example you can create a small user defined shell. Today I will show you how this can be done.
At first we need the following: MemoryStream, StreamWriter and namespaces System.Reflection and System.CodeDom.Compiler.
This works as follows: Define a source code that will be compiled in memory with the following method. To ease the work you can predefine namespaces, functions, etc. In my snippet I created a Windows-Forms-Project. For that reason I intentionally make use of MessageBox.

, , , , ,

WPF: How to create squared custom controls and use them for board games

It may seem simple to generate a squared control, but it isn’t. At least when the control should work with different screen resolution and window sizes. Thats a must have for any WPF-Control.

In the old Windows-Forms days we would have listened to a resize-event on the height or width-property and told the otherone the new size. Of course, we can use the same way in a WPF-Application, but thats not the way to do it.
In WPF we use XAML to do all the surface-coding. Thats important to ...

, , ,

Introducing Events

Sometimes we have to know what happens inside other objects like a collection where new entries are added or removed. So we have to make use of a nice feature called Events.
In this post I will give you a first insight in Events with a snippet for an observable collection called WatchedList. Observable collections are part of the .Net Framework since version 3.0.
At the time i needed the observable collection I worked with version 2.0 of the framework. So please excuse my bad coding convention. But ...

,

Introducing Extension Methods

With Extension methods you can extend the existing funtionality of objects and types. In this case we will extend the functionality of an Array.
So we need to create two extensions. One for changing the size and one for appending a new element.
What do we need for this? At first we need a static class and we call it ArrayExtensions.

, , , ,

Simple Ini class

This time I have a small snippet for you which is for simple processing of ini files. I programmed the snippet a long time ago. At this time I used an other naming convention for code than now. I hope this can be useful. Ini files are still in use for simplified storage of settings. Especially for compatibility reasons to outdated versions of programs, or simple for converting.

, , ,

Previous Posts

Theme created by thememotive.com. Powered by WordPress.org.