Executable directory where application is running from?

This is the first post on google so I thought I’d post different ways that are available and how they compare. Unfortunately I can’t figure out how to create a table here, so it’s an image. The code for each is below the image using fully qualified names. My.Application.Info.DirectoryPath Environment.CurrentDirectory System.Windows.Forms.Application.StartupPath AppDomain.CurrentDomain.BaseDirectory System.Reflection.Assembly.GetExecutingAssembly.Location System.Reflection.Assembly.GetExecutingAssembly.CodeBase New … Read more

Can VB.NET be forced to initialize instance variables BEFORE invoking the base type constructor?

If you have virtual members that are going to be invoked during construction (against best advice, but we’ve already agreed on that), then you need to move your initialization into a separate method, that can protect itself against multiple calls (i.e. if init has already happened, return immediately). That method will then be invoked by … Read more

How can I cancel Task.WhenAll?

Use TaskCompletionSource<T> to create a task for some asynchronous condition that does not already have an asynchronous API. Use CancellationToken.Register to hook the modern CancellationToken-based cancellation system into another cancellation system. Your solution just needs to combine these two. I have a CancellationToken.AsTask() extension method in my AsyncEx library, but you can write your own … Read more

FileStream Vs System.IO.File.WriteAllText when writing to files [closed]

FileStream gives you a little more control over writing files, which can be beneficial in certain cases. It also allows you to keep the file handle open and continuously write data without relinquishing control. Some use cases for a stream: Multiple inputs Real time data from a memory/network stream. System.IO.File contains wrappers around file operations … Read more

VS 2008 breakpoint will not currently be hit. No symbols have been loaded for this document

This may be an old question, but I wanted to answer it after I found a solution for this very problem because it was one of the most complete questions asked in regards to this topic. Intro My project is an ASP.NET application, but the base problem will happen on WinForms as well. The problem … Read more

Lambda property value selector as parameter

private string MyMethod(int testParameter, Func<MyObject, string> selector) { return selector(_myObject); } When using Func delegates, the last parameter is the return type and the first N-1 are the argument types. In this case, there is a single MyObject argument to selector and it returns a string. You can invoke it like: string name = _myClassInstance.MyMethod(1, … Read more