Skip to content
wpdev

.NET / C#

.NET

Uncovering a bug in Attribute.GetHashCode

2017-03-26
By: Kevin Gosse
On: March 26, 2017
Tagged: .NET, C#

It started from a question on StackOverflow. The following code will return inconsistent value for the hashcode of the attribute: View the code on Gist. This will print the output: 1234567 0 0 We can see that the hashcode value changes between the first and second invocation. Even more interesting, commenting line 3 seems to fix the behavior and GetHashCode will always return 1234567. To understand what’s going on, we first need to look at the source code of the Attribute.GetHashCode method: View the code on Gist. In a nutshell, what it does is: Enumerate the fields of your attribute Find the first field thatRead More →

[UWP] NavigationService with back button handler priority

2016-02-21
By: Kevin Gosse
On: February 21, 2016
Tagged: .NET, C#, universal apps, WinRT, wpdev

There’s an issue I’ve encountered in every single of my UWP applications, so it’s very likely you know about it. In Universal Apps, you can subscribe to the SystemNavigationManager.GetForCurrentView().BackRequested event. It’s usually done firsthand to mimic Windows Phone’s behavior where pressing the back button loads the previous page in the back stack. So far, so good. But then comes the moment when you need to implement a back button behavior that is specific to a page. For instance, you have a popup and you want to dismiss it when the user presses the back button. So you subscribe once more to the SystemNavigationManager.GetForCurrentView().BackRequested event, implementRead More →

[UWP] Bandwidth adaptive image control

2016-01-13
By: Kevin Gosse
On: January 13, 2016
Tagged: .NET, C#, universal apps, WinRT, wpdev

There’s a dilemma you probably faced if you’ve written a mobile application displaying a large number of pictures. You could display gorgeous hi-resolution pictures, but if you do so, you’ll provide a poor experience to users who use your app on the go. Particularly, users with a poor mobile connection who will have to wait minutes before the pictures are displayed. You may also discontent users with limited data plans, who don’t want to eat gigabytes of data just to display your pictures. On the other hand, if you settle for low-resolution pictures, you’ll provide a sub-optimal experience you are at home, with an unlimited andRead More →

[uwp] Animation orchestration using Caliburn.Micro coroutines

2015-10-25
By: Kevin Gosse
On: October 25, 2015
Tagged: .NET, C#, Caliburn.Micro, universal apps, wpdev, xaml

MVVM is a commonly used design pattern for XAML-based applications (WPF, Silverlight, and now WinRT). I won’t go into a full description of the pattern, but I’d like to spend some time on a design issue I’ve encountered ever since I’ve started Silverlight/WinRT development. The issue Everybody will tell you: nowadays, for a good UX, animations are a must-have. XAML applications have a very powerful animation system based on storyboards, but it doesn’t fit well with MVVM. How so? One of the recommendation when using the MVVM pattern is to make a clear separation between the viewmodel and the view. The viewmodel should have noRead More →

Should I await the last call in a method

2015-09-12
By: Kevin Gosse
On: September 12, 2015
Tagged: .NET, C#, WinRT, wpdev

I came to write a code looking like this: Then I stepped back a bit and thought: OnNavigatedTo is an event, and its return type can’t be changed from void. Therefore, is there a point in awaiting the last asynchronous call of the method, as this will provide no information at all to the caller? Would it result in a useless call to the dispatcher, just to execute an empty callback? Actually, is the compiler smart enough to detect this case and remove the seemingly useless await? Understanding what’s going on How to figure out whether the last await call has any impact? Let’s say I add some code atRead More →

Debugging Visual Studio from Visual Studio

2015-09-05
By: Kevin Gosse
On: September 5, 2015
Tagged: .NET, Visual Studio, Windows 10, wpdev

When used to install various extensions and beta SDKs on your development machine, it often occurs that Visual Studio starts acting erratically, even to the point of stopping working. Sometimes, the workaround can be easily found by browsing through specialized websites, sometimes it can be much harder because you’re lacking information on the precise issue. That’s when trying to debug your IDE can help putting you in the right direction. I encountered such situation today, so I thought it would be interesting to share the few steps I had to go through. The symptoms It all started when trying to create my first Windows 10 project onRead More →

Label placement issue in Telerik RadCartesianChart

2015-08-30
By: Kevin Gosse
On: August 30, 2015
Tagged: .NET, C#, Silverlight, Telerik, wpdev

This is a strange corner-case in the way Telerik’s RadCartesianChart control handles the placement of labels. There is very little chance that you ever meet this bug, but if you do it can be quite unsettling, and that’s why I chose to cover it in this post. The setup First, what is this bug about? Let’s start by displaying a simple chart. The only twist here is that I use a converter to display the labels, because I want the user to be able to change the format dynamically: Nothing fancy in the converter: it parses the input if it’s numeric, then calls string.Format withRead More →

Dispatcher.Yield – When and how to use it on WinRT

2015-05-15
By: Kevin Gosse
On: May 15, 2015
Tagged: .NET, C#, WinRT, wpdev

That’s an issue happening from time to time. You need to do some lengthy computation on the UI thread (for instance, a page navigation), and you want to display a progress indicator to ease up the user waiting. It’s possible on WinRT thanks to the compositor thread: a dedicated thread for animations that don’t impact the page layout, making them run smoothly even when the UI thread is busy. Some built-in controls automatically use the compositor thread, such as the ProgressRing. So, what the issue could be? Letting the UI refresh Let’s say that when the user taps on a button, we want to displayRead More →

Pushing Telerik controls a bit further: keeping the RadWindow open when navigating to another page

2014-09-12
By: Kevin Gosse
On: September 12, 2014
Tagged: .NET, C#, wpdev

The RadWindow is a nice control for Windows Phone provided by Telerik. It allows you to display a popup, along with some neat helpers, especially for the popup placement. Unfortunately, I just ran along one of the limitations of this control. My application displays a list of pictures. When tapping on a picture, I use the RadWindow to display some detailed information on the picture. In the popup, there’s also a “fullscreen” button. When pressed, the button navigates to a new page, where the user can view the picture in full screen, and zoom to his convenience. So far, so good. That’s when I noticedRead More →

Give that memory back!

2013-11-11
By: Kevin Gosse
On: November 11, 2013
Tagged: .NET, C#, wpdev

A weird behavior (one more) I noticed on Windows Phone, thanks to a question on StackOverflow (once more). First, let’s create a simple Windows Phone application. The first page will contain three buttons: the first one navigates to another page, the second one displays the amount of memory used (by calling Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage), and the last one will forcefully call the garbage collector, wait for the finalizers to execute, and collect the memory freed by those finalizers: In the second page, we simply create a few objects and bind them to a grid. The sole purpose is to simulate a page that would use a largeRead More →

Posts navigation

1 2 3 Next

Recent Posts

  • Uncovering a bug in Attribute.GetHashCode
  • [UWP] NavigationService with back button handler priority
  • [UWP] Bandwidth adaptive image control
  • [uwp] Animation orchestration using Caliburn.Micro coroutines
  • Should I await the last call in a method

Archives

  • March 2017 (1)
  • February 2016 (1)
  • January 2016 (1)
  • October 2015 (1)
  • September 2015 (2)
  • August 2015 (1)
  • May 2015 (1)
  • April 2015 (1)
  • March 2015 (3)
  • October 2014 (1)
  • September 2014 (1)
  • November 2013 (1)
  • August 2013 (1)
  • May 2013 (1)
  • February 2013 (1)
  • December 2012 (1)
  • October 2012 (2)
  • July 2012 (1)
  • May 2012 (1)
  • February 2012 (1)
  • January 2012 (4)

Follow me on Twitter

My Tweets

Designed using Dispatch. Powered by WordPress.