async void – How to Tame the Asynchronous Nightmare
Most intermediate dotnet devs writing async await code in C# will come across async void at some point. Here's a creative solution for avoiding the headaches.
Content that is all about programming and coding in .NET (dotnet)! Find examples of code often written in C# along with tutorials.
Most intermediate dotnet devs writing async await code in C# will come across async void at some point. Here's a creative solution for avoiding the headaches.
As a C# developer, understanding the different simple data types in C# and when to use them is crucial for writing efficient and maintainable code. I've been trying to spend more time this year putting together some content aimed at really introductory level programming. There's plenty of resources available online, but I want to do my part to ensure I can help break down some of the barriers for people getting started on their programming journey. In this beginner's guide, we will look at the basics of the most commonly used simple data types in C#, including int, float, double, byte, char, bool, and string. We will also look at how these data types differ from each other and when to use them in your C# programming! Integer Data Types The most commonly used integer data types in C# are…
I love dependency injection frameworks ever since I started using them. Specifically, I'm obsessed with using Autofac and I have a hard time developing applications unless I can use a solid DI framework like Autofac! I've recently been working with Xamarin and found that I wanted to use dependency injection, but some of the framework doesn't support this well out of the box. I' was adamant to get something going though, so I wanted to show you my way to make this work. Disclaimer: In its current state, this is certainly a bit of a hack. I'll explain why I've taken this approach though! In your Android projects for Xamarin, any class that inherits from Activity is responsible for being created by the framework. This means where we'd usually have the luxury of passing in dependencies via a constructor and…
Organizing code into Autofac modules can make maintaining code much easier and improve extensibility! It all starts with the Autofac module class. Check it out!
In Unity3D, the scripts we write and attach to GameObjects inherit from a base class called MonoBehaviour (and yes, that says Behaviour with a U in it, not the American spelling like Behavior... Just a heads up). MonoBehaviour instances can be attached to GameObjects in code by calling the AddComponent method, which takes a type parameter or type argument, and returns the new instance of the attached MonoBehaviour that it creates. This API usage means that: We cannot attach existing instances of a MonoBehaviour to a GameObject Unity3D takes care of instantiating MonoBehaviours for us (thanks Unity!) ... We can't pass parameters into the constructor of a MonoBehaviour because Unity3D only handles parameterless constructors (boo Unity!) So what's the problem with that? It kind of goes against some design patterns I'm a big fan of, where you pass your object's…
Why Consider Using Autofac With Unity3D? I think using a dependency injection framework is really valuable when you're building a complex application, and in my opinion, a game built in Unity is a great example of this. Using Autofac with Unity3D doesn't need to be a special case. I wrote a primer for using Autofac, and in it I discuss reasons why it's valuable and some of the reasons you'd consider switching to using a dependency container framework. Now it doesn't need to be Autofac, but I love the API and the usability, so that's my weapon of choice. Building a game can result in many complex systems working together. Not only that, if you intend to build many games it's a great opportunity to refactor code into different libraries for re-usability. If we're practicing writing good code using constructor…
Looking to get started using dependency injection with Autofac in your projects? Here's a quick primer on what it is and how to get going for your next project.
Unity3D Default .NET Framework I recently wrote that I wanted to start writing more Unity3D articles because I'm starting to pick up more Unity3D hobby work. It felt like a good opportunity to share some of my learnings so that anyone searching across the web might stumble upon this and get answers to the same problems I had. Unity3D as of 2018.1.1f1 (which is the version I'm currently using), still defaults to using .NET 3.5 as the framework version. Nothing wrong with that either. I'm sure there are reasons that they have for staying at that version, probably because of Mono and cross platform reasons if I were to guess, so I'm not complaining. For reference, this setting in Unity3D is referred to as "Scripting Runtime Version". So if you're googling more about this later, that's what Unity calls it.…
C# Dev Connect 1: Intro to Threading In my last post, I mentioned we'd be hosting a C# Dev Connect meetup at our Magnet Forensics HQ in Waterloo. I figured I'd post to talk about how the event went so that if you couldn't make it, you'll have an idea for next time (and if you did make it, maybe you can comment on how you thought the event went). Our first Dev Connect was lead by a colleague of mine, Chris Sippel, who wanted to give a talk on threading basics in C#. Threading can quickly become a really complex topic, so Chris wanted to keep it high level and talk about the different approaches you can use to start threading in your C# applications. https://twitter.com/Chris_Sippel/status/557655585492328450 Dev Connect: Before the Talk Before Chris gave his talk on threading, we…
MyoSharp If you haven't checked it out already, my friend Tayfun and I created an open source C# wrapper for Thalmic's Myo. It's hosted on GitHub over here, so you can browse and pull down code whenever you want. We've had some great feedback from users of our API, so we continue to welcome it (both positive and negative!) in order to improve the usability. Thalmic has plans to release a firmware update to allow more data to be accessible through their API. Right now, MyoSharp is a bit out of date, but once this big firmware update lands we'll take some more time to get it up to date again. Remember, it's open source so you can feel free to contribute! Troubleshooting The most common question I receive is "I keep getting an exception about not being able to connect…