1/ If you have ever worked with Windows Forms, you may have noticed that the icon that appears in solution explorer changes when it contains a 'designable' type, and that when you double-click on any file with that icon, it opens the designer.
2/ If you play around with this a bit, you may also notice that if you change a class to descend from System.Windows.Forms.Form, it will become designable, and the designer lights up. I doubt many people have thought about how that works.
3/ However, given the behavior, we can tell that somehow the project system must be able to detect when a class becomes designable… and how does it even know what it means to be designable anyway?
4/ The answer is relatively straightforward but has had some performance consequences throughout versions of VS. A class is designable based on an attribute, specifically the designer attribute.
5/ This also specifies the category, which enables invoking a component versus forms design experience. This attribute is placed on the class, but can appear anywhere in the base hierarchy. This enables support for things like inherited forms.
6/ However, the end result of this is that to determine designable types a bit of code has to scan the types within the file, resolve their base classes, walk those, checking each for a DesignableAttribute.
7/ This has to be done any time there are changes to the file, because you could be changing the hierarchy or adding the attribute at any point in time. There are a bunch of caveats and optimizations that take place to mitigate this, but it's always been a bit painful.
8/ You may notice that if you change a class to descend from a designable type, the designer isn't necessarily immediately available and the icon in Solution Explorer takes a little bit to change.
9/ It's usually not long, but the reason for this is that the scanning for these changes happens asynchronously. Prior to Roslyn, this scanning actually happened on the UI thread; however, it happened only when VS detected it was in an idle state.
10/ Even though Roslyn does this asynchronously it still needs to tell the project system what it's found. This allows the icon to be updated and the designer to be invoked. In some of the project systems in VS, this still requires calling on the UI thread, though not for Core.
11/ I've mentioned before some of the fragility we had with early versions of Windows Forms. There were several reasons for this, some I've discussed already, but one that was surely confounding to folks was when their file would suddenly become undesignable.
12/ The most frequent reason for this was because they added a non-designable type ahead of the designable type in their file (we used to only scan the first type for performance reasons).
13/ So, if they put a n enum at the top of their file/namespace, ahead of their Form, they wouldn't be able to open the designer any longer.

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Anson Horton

Anson Horton Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @AnsonHorton

25 Jun
1/ In the late 90s we were busy on the ambitious project of Visual Studio .NET, introducing a new runtime, new languages, and a new shell. The last involved combining several existing shells, VJ/VI/MSE 6, VC6, and VB6.
2/ This led to many difficult discussions, incredibly complicated and confounding technical challenges, and the most difficult problem - what side of the environment should the Solution Explorer dock to by default?
3/ In VC6, file view was on the left. In VJ/VI/MSE and VB6 the project explorer was on the right. You'd think that since you could move it, and that was persisted, it wouldn't matter that much.
Read 5 tweets
24 Jun
1/ In the VS 2005 release there were many new features for the C# IDE experience, several of which would generate code. An example was implement interface, which was proffered as either a 'smart tag' or through the context menu.
2/ Another was generate method stub, where we would optionally create a method if you consumed it without having declared it first. When we released VS 2005, these features would generate stubs of the following form (this is the code gen for implementing IComparable<Widget>):
3/ public int CompareTo(Widget other)
{
throw new Exception("The method or operation is not implemented.");
}

The C# community was, not surprisingly, somewhat confused (and often livid) that the code generation didn't use NotImplementedException instead.
Read 11 tweets
23 Jun
1/ @DesignPuddle asked why Solution Explorer search is so much slower than Goto All when searching for files. This is seemingly nonsensical because Goto All is presumably searching for everything while solution explorer search is searching less, right? Well… it is nonsensical,
2/ the search should be much faster, and the reason it’s slow has a lot to do with how it was initially designed versus what it’s now being used for. So, lets dig in a bit.

Both Goto All and Search in Solution Explorer are extensible via providers. However, the providers are
3/ different, and that’s critical to understand the difference. Search in Solution Explorer was added in VS 2012 as I recall. It works by kicking off an asynchronous task that invokes each provider. It currently does this sequentially instead of in parallel. There are really two
Read 26 tweets
14 Jun
1/ It's been very busy at MS ever since the new year started, and you've probably seen a bit of what we're working on with Visual Studio 2022 (devblogs.microsoft.com/visualstudio/v…).
2/ I'm going to go further back in history though, and talk about a defining moment for Visual Studio .NET (2002) and really all of Microsoft. In early 2002, Bill Gates sent a memo to the entire company that kicked off the Trustworthy Computing initiative.
3/ There had recently been a raft of serious computer viruses, coupled with the September 11th terrorist attacks; it was a turning point for the country, industry, and company.
Read 18 tweets
4 Jan
One of the stories that my first manager used to tell, that I always got a kick out of was the following. Context: Think Week was a week that Bill Gates used to take every year to learn about a huge variety of topics, and folks at MS would submit papers/bits. It was a big deal.
"I joined Microsoft on 3/19/99 and found out I was working on a new language. The first week was a blur just getting up to speed and I don't think I even installed the complier (not that it did much then - I think you could define an interface but not use it yet).
In my second week (3/27/99) I get an email from Drew saying that Bill [Gates] wants the C# Language spec and the latest build of the compiler by 4.30 (Note that it was 4.30 not 4/30). I'm still getting used to US dates so I see 4.30 and think it's 4:30pm that day.
Read 8 tweets
3 Jan
Incremental rebuild was a feature of the C# compiler which was meant to increase the throughput after an initial build. It worked on the principle that changes in between builds are localized, and that the information gathered by the compiler from previous builds wouldn't be
entirely invalidated; specifically, some of the information and, indeed, the assembly itself could be updated in an incremental fashion resulting in faster builds.
Both the VS 2002 and VS 2003 compilers exposed this option through the /incr switch on the command line, and the ‘Incremental Rebuild’ option in the Advanced tab of Project Properties. In 2002 incremental rebuild was enabled by default for all project types.
Read 22 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(