Posts

Debugging information and visual studio

Image
Without debugging information there is no debugging. By default debugging information is included when you build your project with the Debug configuration. Configuring debug information When you create a new project with .NET , Visual Studio provides two default build configurations in your project. Debug and Release . A solution build configration defines which projects are built and deployed for which target platform ( x86 , x64 or Any CPU ) although the platform can be overwritten by the project build configuration. The solution file ( .sln ) holds the values you configured. A project build configuration can define anything you can configure in the project file ( .csproj ). But they are mainly used to configure the target platform, if the output should include debugging information and if the complier should optimize the code. When debugging information is included the default ( Portable for .NET Core and Pdb-only for .NET ) is that a seperate symbol file is beeing create

Gluing things together

Gluing things together One of the most important things in coding is how to hold it together. In this short article I will share some thoughts on callbacks, events, observables, promises and tasks. This is what I have experienced in my time programming and I would be glad if you could share if you don't agree with me on something. Why callbacks are bad When I started programming some years ago I started with C# and Javascript. While .NET already had the Event in Javascript callbacks were everywhere. Then the word "callback hell" was coined. In short callbacks and also Events for that matter are bad because they defere the code execution to some other place which can be hard to find especially when you are following from one callback to the next for multiple steps. Therefore it pollutes the code and can separate concern which should not be separated. Why callbacks can be good Defered execution is not always bad. To create modulation and structure callbacks an

Creating a cordova plugin and using it with ionic

In this article I will show how you can create a cordova plugin and use it in an ionic project. Prerequisites Before you can start you need to install the following tools. Node 6 LTS NPM 3+ Creating a cordova plugin Initialising the plugin To create the project files for the cordova plugin you can use use plugman which is a nice cli. I was using version 2.0.0. > npm install -g plugman ... > plugman --version 2.0.0 > plugman create ^     --name PingPong ^     --plugin_id cordova-plugin-pingpong ^     --plugin_version 0.0.1 > cd .\PingPong `plugman create` will create the following file/folder structure. PingPong   src                             <- Folder for native code   www                          <- Folder for JavaScript API which calls native code     PingPong.js                          <- Public API    plugin.xml                 <- Plugin configuration file The next step is to add the platforms y

Windows message pumb / Dispatcher / RealProxy

Not so long ago I had to integrate a COM component into an application. The catch was the application had no Windows message pumb and the COM component uses exactly this message pumb for some communications. So I need to create a thread with its own message pumb and then dispatch the calls to the component to the thread holding this message pumb. Creating a thread is simple and quickly done. _thread = new Thread(RunThread) { Name = nameof(MessagePumpDispatcher), IsBackground = true } _thread.SetApartmentState(ApartmentState.STA); _thread.Start(); And to start a new message pumb I can use the Dispatcher type. _dispatcher = Dispatcher.CurrentDispatcher; try { Dispatcher.Run(); } catch (ThreadAbortException) { Thread.ResetAbort(); } Dispatching work to this thread can be achieved by using the Invoke method on the Dispatcher. _dispatcher.Invoke(action); This is the whole class. Now to send all calls of the component to the correct class I could either wrap

Components of Tasks & Threading in .NET

Image
I recommend understanding the basics of async and await before you read this article. This is a good introduction from Stephen Cleary. As you might know simply using async and await doesn't mean your code is executed on different threads. To achieve this you must use Task.Run , TaskFactory.StartNew or the Task Parallel Library . This is an introduction in the different components at play when you want to schedule tasks on different threads. TaskFactory The TaskFactory is a simple container where you can configure options for the creation and continuation of Tasks. Furthermore you can specify an canncelation Token which will be used by all Tasks created through this factory. And lastly you can define your own TaskScheduler. It's your choise if you want to use a TaskFactory to start a new task or if you want to start a task directly trough Task.Run. MSDN TaskFactory TaskScheduler The TaskScheduler is responsible to run the next task on the correct