share
Stack OverflowWhy Windows 7 isn't written in C#?
[+49] [27] Joan Venge
[2009-04-23 19:44:01]
[ c# .net windows ]
[ http://stackoverflow.com/questions/783238] [DELETED]

I saw a similar question [1] about the reason Google Chrome wasn't written in C#. But with the upcoming version of Windows and Microsoft's flagship language, I am having a hard time understanding why Microsoft isn't pushing C# to its fullest potential to give it more exposure via their market share?

In addition can be interpreted as "Is C# and the .Net framework suitable to run a modern OS like Windows 7"

Btw this is not a flaming question, but curiosity. I use C# daily and really love it.

(46) A better question might be is C# and the .Net framework suitable to run a modern OS like Windows 7. - JoshBerke
Good point, added to the question. - Joan Venge
Can anyone name a single operating system that is written using a language that requires a VM. There's no garbage collection on the iPhone OS X version so that's probably a good indication why not - Chris S
(22) COSMOS, Singularity, SharpOS - Mehrdad Afshari
It should be ...suitable to write a modern OS... right? - Jay R.
(1) @Chris, C# doesn't require a VM. - Robert S.
No but it's compiled into one that requires one - Chris S
In my (absolutely personal) opinion it is a nice experiment but in the next decades we will not see IL-VM-based OSses. - RĂ¼diger Stevens
(8) @Chris, you can implement a C# compiler that does not require a VM. In other words, C# can live without the .NET Framework. - Robert S.
(8) C# without a VM (or rather GC, to be specific) wouldn't have any advantages over C++. - Pavel Minaev
(8) you don't need a VM for a GC either. - Sekhat
(1) Among only 10,000 other reasons, C# needs the .NetFramework to run. .NetFramework needs windows to run. C does not. - Lienau
(1) @Lienau: C# itself doesn't need .NET to run. Most C# applications need .NET, true, but C# doesn't. However, how much of a payback would there be in writing an OS in C# without .NET? This would be a really big project, and cost billions of dollars, so there would have to be a compelling reason. - David Thornley
@DavidThornley: So, that is not C#, that is new C# which is better call it C#++ - Masoud M.
(1) @Masoud M.: No, that's C#. There's an ECMA standard for C#, and doesn't mention .NET. C# is not inherently a part of .NET or Mono or any such thing. - David Thornley
[+205] [2009-04-23 19:45:32] Mehrdad Afshari

Because there is a HUGE working code base in C.


(67) Any discussion about C#'s speed, or .NET's usefulness, or whatever is moot when this answer is taken into consideration. - Robert S.
(2) It's only 40M lines of code, right? - Joan Venge
(12) @Joan: Depends on the meaning of M: xkcd.com/394 - Mehrdad Afshari
I hope it's C++ not C - Chris S
I think Windows kernel is pure C - Mehrdad Afshari
I meant million. - Joan Venge
(1) And I meant it as a joke :) - Mehrdad Afshari
I also think C/C++ - Syed Tayyab Ali
(1) Definitely Windows does have C++ code. I don't work for MS, so I don't know, but I think the kernel isn't in C++. - Mehrdad Afshari
(10) But Linux is only 4 million, that's why it's better! - Chris S
Haven't realized it, sorry :) - Joan Venge
(6) @Chris - The Linux kernel is around 5 million LOC, but a distro is closer to 200+ million. blogs.computerworld.com/… - Mark Brackett
(31) I just realized you can now get comments voted up by posting XKCD links. - Michael Myers
(1) @mmyers: lol. Let's go memorize the numbers to use them efficiently! - Mehrdad Afshari
(49) Wait wait wait. Did you say "working code base". :) - GMan
(6) @GMan: It works on my machine :-) - Meinersbur
This has nothing to do with it. It says in the T&C's of .Net that it shouldn't be used for mission critical applications. C# will never be used for low level systems development. - Mark
@Mark 1. [citation needed] (I know there was such a thing in Sun Java EULA, but I don't remember it in .NET). 2. Of course Microsoft is not bound by the EULA if its own product! - Mehrdad Afshari
1
[+103] [2009-04-23 19:46:30] JaredPar

I think you need to ask a slightly different question to be more accurate.

Why didn't Microsoft rewrite Windows 7 in C#

There is a very simple answer to that one. Windows comprises an estimated 50 million lines of code. Rewriting 50 million lines of code just to change languages is a ton of work for very little / no profit.


+1: And rewrite C# too. - Masoud M.
2
[+50] [2009-04-23 19:47:01] JoshJordan

Basically because it is not ideal for an Operating System. C# is, by definition, a high-level language that is built on many layers of features and (usually) the .NET framework. Memory management is abstracted away from the developer and for such a critical application that is under incredible scrutiny for efficiency and performance, this is not an ideal environment for Op Sys development. The list goes on, but that's a big part of it.


(23) Ah, but this the old thinking! The new thinking in system architecture is to design a full opperating system in which the CLR (or VM) along with the Jitter is pushed down right to the lowest level. It would sit right on top of a small EFI kernel. - David Leon
(2) Very interesting comment. Can you provide a link to some verification? - JoshJordan
(6) A few years ago people would have said the same thing about writing an operating system in C rather than Assembly. Yes, there's a difference between the two comparisons, but as computers become faster and faster, I think it's inevitable that operating systems will more in this direction. - musicfreak
(5) @musicfreak: The difference is that C compiles to assembler in a straightforward way. It doesn't require additional services. C# doesn't do its own memory management, but requires garbage collection. Computers will get faster, but there will always be apps that require all the performance they can get, so slowing down the kernel is a real bad idea. - David Thornley
(3) We actually have production operating systems based on .NET. Specifically the .NET Micro framework. - Jonathan Allen
CLR (or VM) would be thought-of (or optimized) to use as Windows 7 Kernal (uproarious thought) - Ramiz Uddin
3
[+32] [2009-04-23 19:46:23] Joe Philllips

They're probably still researching an OS built in something like C# ( Microsoft Singularity [1])

Singularity is a research project focused on the construction of dependable systems through innovation in the areas of systems, languages, and tools. We are building a research operating system prototype (called Singularity), extending programming languages, and developing new techniques and tools for specifying and verifying program behavior.

There is an interrupt dispatcher written in C but once it finishes, it gets dispatched to compiled C#.

[1] http://research.microsoft.com/en-us/projects/singularity/

(2) Well done! I was going to mention this but you beat me to the punch. I love the notion of Singularity. Let's have it. Bring it on. - David Leon
(1) But what are all these .cpp/.h files you can see in Singularity?! - Chris S
(3) Singularity does have C/C++/ASM. COSMOS just has ASM I think. All C OSes do have assembly bootstrap files too. It's not considered the kernel language though. - Mehrdad Afshari
That was from looking at /Kernel/Native (e.g hal.h, thread.cpp) but I don't know the code base enough to judge well - Chris S
(2) I have listened to podcast with Singularity dev/owner and I think he said that it's purely a research project and even though some ideas do spill out in mainstream, the OS itself will never do. - bychkov
@Mehrdad "It's not considered the kernel language though" What does that mean? - RussellH
I think maybe the question could be re-phrased as "Why can't a large portion of Windows 7 be written in C#" - RussellH
4
[+17] [2009-04-23 19:46:25] Promit

Because rewriting 60 million lines (no, I'm not exaggerating) of perfectly good C/C++ code just to prove a point would be insane? I would think that's the main reason.


(4) Seems everyone is slightly at odds of how many lines of code it actually is. Only a 20 million difference in this post alone. - Terry
Also I wonder if they count comments, spaces, etc since there is no standards for LOC AFAIK. - Joan Venge
(13) Yes. You are exagerating. From the code I have seen from Microsoft, "slightly good" would be stretching it. "Perfectly good" is an extreme exageration. - BubbaT
(23) @BubbaT: I'd be willing to bet their code is better than yours - Matthew Whited
(2) For a code base the size of Windows, estimates varying by 20 million is pretty much in the noise level. (Having worked in a different code base of equivalent size....) As for how to count LOC, some versions of Visual Studio include code metrics. LOC for C# does not include comments, blank lines, or bracket-only lines. Re: MS code quality, I've been very impressed in recent years. .NET is excellent. I think their focus on security for XP SP2 really improved their focus on code quality in general. - Cylon Cat
5
[+15] [2009-04-23 19:45:51] Aardvark

One reason is that Windows Vista was not written in C#. Or XP, or 2000, or NT4...

Windows may be one of the biggest code bases in the world, and maintains decent backwards compatibility. Rewriting it in a new language isn't likely.

There was some other issues back in the longhorn days [1]... They quote some guy named Joel Spolsky, so take this with a gain of salt... ;)

[1] http://www.microsoft-watch.com/content/developer/the%5Fdirty%5Flittle%5Fsecret%5Fabout%5Flonghorn.html

Very true. They didn't write windows 7 from scratch. Some people are even calling it Vista Second Edition. To write it in C# would mean that they would have to basically throw out everything, and rewrite the entire OS. - Kibbee
(1) some guy named Joel Spolsky who btw is also a co-founder of stackoverflow - Pacerier
(1) (hence the winky smile) - Aardvark
6
[+12] [2009-04-23 19:47:05] John Saunders

Do you use C# to create device drivers? I bet you don't, nor does anyone else? So, why would Win7 device drivers be written in C#?

Do you often scrap existing code and rewrite it, just for marketing purposes? Neither does Microsoft.

This is a pretty silly question, if you think about it.


(8) IE rewritten in C# would be a nice marketing exercise - Chris S
(14) Marketing exercise for what? To market C# or IE? Which of them needs marketing? Who would be impressed by Microsoft wasting time rewriting "working" code for no apparent benefit? - John Saunders
(10) I think a WebKit based IE will make a MUCH BETTER marketing! - Mehrdad Afshari
Is there any reason why you couldn't write device drivers in C#? - Ellery Newcomer
(2) There's almost nothing you could do in C# that would not require support from the runtime. The runtime will certainly not run in Kernel mode! - John Saunders
(5) Not correct. In Singularity, for instance, everything runs in kernel mode. Process isolation is achieved by managed code verification techniques (called SIPs in Singularity). It's a completely software based approach of enforcing invariants. Device drivers can be written (and are written in some managed OSes) in C#. - Mehrdad Afshari
@Mehrdad: Does Singularity use the normal .NET Framework running in Kernel mode? Is it a subset? Is it a modfied .NET Framework? Any citation on that? I'd be especially interested in how GC works in Kernel mode in the .NET Framework, and how they mapped the threading APIs, AppDomains, etc. - John Saunders
@John: Definitely, it's not the Windows .NET Framework (as it uses Windows API) but it's CLI compliant, and yes, indeed, it runs in kernel mode (as anything in Singularity). The thing is, at the lowest level, there are no services (JIT and other stuff). A minimal CLI is compiled directly to native code. Singularity runs only managed code so the whole memory management system is GC oriented. I don't see a problem here. BTW, you could take a look at the source if you're interested in its implementation. - Mehrdad Afshari
(2) You can also look at the .Net Micro Framework. It's a subset of the CLR running on the bare metal. (I'd like to see an x86 compiler for it) - Matthew Whited
Anonymous downvotes don't help improve SO. - John Saunders
(28) No offense but your way of speaking is kinda rude.People are just exchanging some ideas. If you don't like this questions,then just pass it. - Braveyard
@Aaron: did you comment on the correct answer? Where was I rude in this answer? - John Saunders
(30) -1 for "Silly Question". Don't be so arrogant and distasteful. This is a perfectly valid question. - Callum Rogers
(1) Thanks for saying why you downvoted. Most downvoters don't have the guts to say why. And, BTW, it was a silly, or at best, ignorant, fan-boyish question. That is to say, if I had asked that question, it would mean I was being silly, or being a fan-boy. The idea of a company spending big bucks on a software project as a marketing move is unrealistic in the extreme. - John Saunders
(7) I don't think it is a silly question. Just because someone doesn't know something, asking about it doesn't make it silly. It's like saying "I know the answer, so obviously everyone should" - Gordon Tucker
@GordonTucker: Thanks for commenting. I may be guilty of assuming people here have roughly the same knowledge I had after four years of CS - 30 years ago. If I had made this comment, it would have been silly. - John Saunders
@downvoter: you don't matter. Nobody cares about you. That's because you don't have the courage to leave a comment saying why you downvoted. Not much self-respect, I guess. - John Saunders
(10) People already downvoted for the harsh tone of the answer, so I'm downvoting because almost a year later you're still deriding people for not commenting even though reasons have already been given. Perhaps you'd like them to provide an address so you can go punch them in the nose? - Brian Ortiz
@Brian: the person who most recently downvoted did not give a reason. Why do you assume that his reason is the same as the other reasons? If it's the same, then I'd appreciate it if he took the time to say, "me too". I'd like them to provide a reason for the downvote. A reason does not provide me with an address - not even an email address. Are you saying that these are actual cowards, and not figurative cowards? - John Saunders
(3) I'm not saying their reasons are the same, I'm saying they're irrelevant given the reasons already stated. Those reasons being your seemingly hostile attitude. - Brian Ortiz
@Brian: you're not making much sense to me. Anyone is welcome to downvote; however, given that there are no negative consequences to being honest and saying why they downvoted, I'm left with no choice but to assume that anyone who does not explain a downvote is simply the worst kind of coward - one who is even afraid to be known as a coward. You will never find that I did anything less than thank anyone who told me the reason for a downvote. - John Saunders
@Brian: I do find it amusing that much of the rancor here stems from my characterization of this question as being "silly". - John Saunders
@Downvoter: you too? - John Saunders
(5) Although I agree with Brian, since you seem to want a reason so badly, I also downvoted because I think you're being rude. - Carter
(1) @Carter: thanks for responding. By "rude", do you refer to the fact that I directly confronted what I believed to be the problem with the question? That is, the fact that it is unrealistic, and that, if I had asked the question, it would have been silly? - John Saunders
(4) By "rude" I mean that, in my opinion, there was a lack of tact in the way in which you confronted what you believed to be a problem with the question... i.e. it's the way in which it was confronted not the confrontation itself. - Carter
@Carter: Thanks for your honesty. That honesty is what I found lacking in certain other downvoters. I'm glad to say I found it in you. - John Saunders
(1) You're most welcome. - Carter
(3) Downvoted because this is the second time you've been rude to someone in my browsing of SO (the other time was to me). And if you want to know why I thought it was rude, the other comments pretty much nailed it. Not everyone on here is as smart as you, John. - alex
@alex: thanks for saying why you downvoted. BTW, it didn't have to do with being smart, just to do with "common sense". - John Saunders
(2) Downvoted because I dont think its a silly question at all. - Canacourse
@Canacourse: thanks for giving the reason for your downvote. - John Saunders
(1) @John - Most of the downvotes (including mine) are probably for the same reason as @Callum's: The "silly question" line is unnecessary, not really helpful to anyone, and IMHO not true when the asker is a newbie. It seems like a freshman student asking a novice question in class, and getting openly mocked by the teacher for asking. I'm not sure why you added it to an otherwise perfectly good answer, or why you haven't removed it by now, but I think most of the downvotes would disappear if you removed it. - Justin Morgan
Also, I suspect most of the 19 upvotes to @Callum's comment are from people downvoting for the same reason. I agree that downvotes should be explained, but I've always felt that upvoting another downvoter's explanation is essentially the same as doing that. - Justin Morgan
@Justin: thanks. I've already explained why I called the question "silly", and my reason still holds. - John Saunders
7
[+9] [2009-04-23 21:14:21] Bryan Rehbein

I think a big part of the reason is performance. A lot of people really don't need large amounts of performance, checking email, browsing the web are all pretty simple and don't need a lot of performance.

However those who actually do need the performance (think Pixar or other companies that do rendering, scientific communities, etc), having the overhead of all this managed code would make computing in these areas extremely difficult because every CPU cycle counts.


(3) As I commented before on another answer: Not true. System protection in Singularity is achieved completely in software, cutting the cost of system calls down (I think at least an order of magnitude lower than a traditional OS). There are many factors to overall performance. - Mehrdad Afshari
(1) But according to the slide deck I saw for Singularity, 23% of the code is unsafe code, with 5% of that written in C++ and asm. - RussellH
8
[+6] [2009-04-23 19:48:11] Bill K

I don't think OS level engineers consider a managed language acceptable, the common excuse is probably performance.

Of course, when C first came out, many didn't believe you could successfully code an OS in anything but assembly.


(10) except that when the world first saw C, someone already had written an OS using it - community_owned
(3) In a sense you are correct. OS level engineers do not consider managed languages acceptable. Unfortunately, they are wrong about that. This is an example of crumugeon-thinking. "Because we have always done it this way, it must always be done this way." - David Leon
That is why research projects such as Singularity exist. Gives crazy engineers the toys that are needed to see what works. - Matthew Whited
9
[+6] [2009-12-06 03:18:56] John Christman

I think the biggest reason is that C# gives away the source.. IL is pretty easily converted back into high level code, and recompiled. This would effectively make Windows Open source.


(2) Haha, that's an interesting view. - Joan Venge
...which would be great! - Callum Rogers
Nah, I've downloaded projects with obfuscated source and it's like having no source. The method and property names have "aaa()" as their names, hard to read and understand. - Chris
It doesn't in any shape or form make it open source. Also you couldn't do anything with the code. Having code in the open with no right to use it only helps in things like internal code(who would want to make internal windows illegally, note that us government and probably other governments can examine it for legally) Considering how easy it is to pirate Windows having the source through code leaks or shared source(both of which I think have given away parts of the code in windows) wouldn't change anything - Roman A. Taycher
Considering how easy it is to pirate Windows having the source through code leaks or shared source(both of which I think have given away parts of the code in windows) wouldn't change anything. - Roman A. Taycher
10
[+4] [2010-01-19 18:11:47] Chris

To add to all the answers here, how about libraries. There are tons of classes in .NET which simply wrap the Win32 API.

Such as Directory.GetFiles(), check it out with reflector, mainly the InternalGetFileDirecotryNames() internal method, it just turns around and calls the Win32 API.

The answer to your question is more than just, "it's hard" or "it takes lots of time". It is also about resources, not to mention having a large code base that's WRITTEN, TESTED, and PAID FOR. To be rewritten, which WILL introduce bugs guaranteed.

Could Microsoft reimplement Windows with a .NET core instead of a Native Core? Absolutely, there is no question it is possible. It would just time to get it right. I don't think anyone would want to wait that long. Parts of the OS will be implemented in Managed Code and perhaps one day the Kernal too, but to just dump out millions of line of working code, isn't going to happen.

Also, if we remove native support in the OS, then apps like Office, IE, Firefox, iTunes, and Visual Studio, will no longer work! There are parts if not the entire product written in C++.

p.s. If the Office team has publicly refused to rewrite Office in .NET, how can you expect the Windows team (the platform Office runs on top of) to rewrite their product?


Thanks but how can the office team can refuse it. MS owns it, right? If they tell them, then they are going to do it. It's not they are a separate company. - Joan Venge
(1) @Joan Venge, because it's a huge product, and it's breath stretches beyond just Windows. There are COM components written which support DDE (dynamic data exchange), that is how you can have Excel 2003 communicate with Word 2007. All of that logic and implementation must be rewritten. I'm sure many of the features of .NET will speed up the process, but it is a huge undertaking, not to mention the current release cycle. They can order the Office team to rewrite in .NET, but how many months or years would that require parallel development, not to mention critical bug fixes when defects appear - Chris
You are right. It's a huge undertaking. - Joan Venge
(2) +1 for "To be rewritten, which WILL introduce bugs guaranteed." - Andrei Rinea
11
[+4] [2009-04-24 00:47:38] community_owned

See the source code in C/C++ of windows XP on Usenet (Win32) and you will understand...


12
[+2] [2009-04-24 20:40:23] JulianR

As others have mentioned: Singularity is a research project and won't see production. However, there's also Midori [1], which is said to be based off the Singularity research project. While most things regarding Midori are pure speculation, it's not unlikely that it will make its way into a future release of Windows. However, don't expect Windows 8 or even 9 to be based on Midori, since the switch to a managed OS would break nearly every application in existence (although .NET based applications might be easily portable). It's more likely that the change to Midori would be gradual, where Midori would run along Windows, or even on Windows as a process.

What's perhaps more interesting than Midori to replace the desktop Windows are the rumors that Midori will power Windows Mobile 8, something much more feasible than desktop Windows.

[1] http://en.wikipedia.org/wiki/Midori_(operating_system)

13
[+1] [2009-08-12 00:08:04] karmasponge

Re-writing any large project written in 'C' or 'C++' (well any language really) would be a long journey which most companies would not risk. Bringing back the OS to the same feature set as previous versions would more than likely take more time than delivering several versions of the existing product.

A more practical approach is to identify a migration path that can occur over time while minimizing impact of existing features (and hopefully adding value at same time).


You'd also have to identify a reason to do it. That's been lacking. - John Saunders
Agreed, if there is no value added then your just wasting your time. - karmasponge
14
[+1] [2011-03-31 08:48:39] Mark

What language is the CLR written in......I rest my case.


Although I don't disagree, that's a weak argument. What language are C compilers written in? Definitely not in a machine language and not likely in an assembly language. The CLR could be rewritten in C#, but it will have to be rewritten. - Jeff Mercado
C compilers are written in C plus assembly. I am not dissing C# I use it and like it. But I wouldn't use it for systems/real time programming. - Mark
15
[+1] [2010-01-07 18:09:26] Amin Emami

C# is a high level language, a great powerful language for creating applications, not operating systems. It runs in a layer (IL) on top of the runtime framework and the runtime framework 'currently' runs over an OS (typically Windows). I am not aware of a .Net runtime framework running on bare metal.

That's the same scenario with Java. There are some small projects of Java Based Operating Systems, but not too serious. And Java has runtime environment for bare metal (again, not too serious). There are even some sort of Java-ready hardware too, but again a very long way to make it commercialized.

To me that is the main issue, of course there are more to it, such as device drivers and so on.


16
[0] [2009-12-21 21:36:49] Igor Zevaka

What would be the point? There isn't much that you can't do in C# that you can in C/C++ using Windows SDK. It would be about 1000 times easier to write a .NET layer over the missing functionality than to rewrite Windows in C#.


17
[0] [2011-06-26 22:51:14] Jerry Coffin

I think a great deal of the real reason has to do with divisions within Microsoft. Windows is produced by one division. C#, .NET, and so on, are produced by another division (developer tools).

To make a long (and frankly, ugly) story short, everything I've seen or heard indicates that the Windows division has little (if any) interest in using C# or .NET at all. From the sounds of things, nearly the only things from the developer's tools division that the Windows division uses at all are the basic command-line compiler and linker -- and even that's pretty grudging, and done primarily because they have no real choice.


18
[0] [2009-11-25 10:21:09] Nimrod Shory

A little bit of a late comment but for googlers like myself..

You have the COSMOS [1] project os that is -

"implemented completely in CIL compliant languages"

It ain't pretty but it is a POC that is going somewhere..

[1] http://www.gocosmos.org/index.en.aspx

19
[0] [2009-04-23 19:46:40] Electrons_Ahoy

Speed / Performance. As fast as the .net JIT VM can be, it's still too slow / heavy to run an OS in.


(1) you wouldn't be able to run the MSIL. there wouldn't be anything to run it. you would have to compile the MSIL into native instructions. - Darren Kopp
(7) Not true. System protection in Singularity is achieved completely in software, cutting the cost of system calls down (I think at least an order of magnitude lower than a traditional OS). There are many factors to overall performance. - Mehrdad Afshari
Yeah, you still have to convert the MSIL into something that can run naively. Running your bare-metal code though a JIT to get to assembly is a bit silly. - Electrons_Ahoy
What I was trying to get at Darren, C# as with Java is converted into IL so it is technically a 4th gen language - Chris S
@Chris: Language generation has nothing to do with being modern or getting converted to other languages. According to Wikipedia: "Fourth-generation languages have often been compared to domain-specific programming languages (DSLs). Some researchers state that 4GLs are a subset of DSLs." - Mehrdad Afshari
I was told something different about 3rd/4th gls and blindly believed that so looks like my point is moot. - Chris S
I never understood why native code that was compiled JIT should be slower than the same native code compiled ahead of time... - nikie
20
[0] [2009-04-23 20:24:05] Botz3000

I've read somewhere on Microsoft Research that they are researching on how to implement a Win32 "Runtime" on a managed operating system. They talked about a managed driver programming interface, too. Too bad i can't find it anymore. I think it might not be impossible, but of course it will always have parts of its codebase written in assembler and C++/C. I'm also sure if the runtime is really the at the foundation of the operating system, the performance overhead would become smaller.


21
[-1] [2009-04-23 21:44:18] jeffamaphone

The runtime's performance and stability, while much improved in the later versions, still isn't to the point where you can build an OS on it and claim 5 9's of uptime, which Windows Server needs to do. You could in theory build the Shell on C#, but there are still a bunch of trade-offs there.


22
[-1] [2009-04-24 01:22:13] Unknown

Garbage collection.

You want a real-time system without needing to pause randomly, sometimes for even more than 1 second. Imagine browsing, listening to music, and watching stock charts, and then BAM, garbage collection.

You can't use an interrupt handler that has random interrupts to clean up memory. See DPC for a small explanation [1].

[1] http://en.wikipedia.org/wiki/Deferred%5FProcedure%5FCall

(5) Windows isn't a real-time operating system (National Instruments RTOS is), and garbage collection isn't necessarily not-real-time (IBM Metronome is). - 280Z28
I meant real-time as in soft-real time. Obviously you aren't going to get perfect time slices, but its better predictability than a garbage collected language like Java/C# where pauses can be as large as a second or more. - Unknown
(3) Well, a "real-time system" is a fairly heavily used and specific term in our industry, and it certainly does not describe any machine running Windows. - JoshJordan
Windows CE is real-time, Josh. - Henrik
Ephemeral garbage collection FTW! Given another 10 years we might have lisp machines back... ;-) - Ukko
Java or .NET 4 (can't seem to remember) have a Garbage Collector which doesn't "stop the world" so this could be avoided. - Andrei Rinea
The problem is nondeterministic garbage collection. - rwong
23
[-1] [2010-04-08 13:44:14] Simon

It's entirely possible to load required runtimes with native API and throw a .NET application at it.. Figuring out exactly what runtimes to load would be the hardest part..

Simon


(2) @Simon: could you please elaborate? - John Saunders
24
[-1] [2009-12-06 03:50:01] Nathan Adams

I think the sole reason why Microsoft didn't write Windows 7 in C# is because .Net is just a set of user libraries that utilize native Windows API. (Repeat of Yassir).

Think it of like this - would you write an operating system in VB6? VB6 is an interpreted language - so it requires an OS with the VB6 runtime, which wouldn't make any sense if you were trying to make an OS that ran in an OS.

I would imagine Windows 7 was written in C, some C++ and Assembly. Something that has this large of a codebase has to have sprinkles of other languages in it for optimization.


(2) Whats with the down vote? .Net is just a wrapper to the Windows API which the API needs to be written in something other than something that relys on the .Net framework. - Nathan Adams
I didn't downvote, but I'd guess your answer contained too many inaccuracies. For example, VB6 was compiled to native code, it just needed a runtime library. So does C++, normally. new and delete must be implemented somewhere, after all. If it's possible to use C++ without its common runtime, why wouldn't the same be possible for VB6 or even C#? - nikie
C++ is an interesting creature to bring up, but both VB6 and C# both require the use of a library. VB6 and C# code will not run without this library. C++, although new and delete are implemented somewhere, I couldn't tell you how, are built into the language rather than a library. You certainly can build C++ programs without iostream, but it won't actually do much - at least nothing you can see. In fact, VB6 did spit out "P-Code" if you wanted it to: bit.ly/d5n4ki - so we are both right. - Nathan Adams
-1: as other answers state, the C# language does not require a library. The current C# compiler, csc.exe does produce code that requires a runtime. - John Saunders
25
[-1] [2010-05-15 03:23:39] Dhawal

C# was new when Vista was under development, MS got lot of experience C++ programmers and code base of Windows Vista ready for performance and feature improvement.

Changing programming language for OS from C++ to C# is not that costly for Microsoft they did it before and I am sure they will do it in future, its just matter of time.


26
[-3] [2010-04-30 23:39:35] amerninja13

Because C#'s code is recognized by Windows itself, not by your computer's hardware (BIOS and/or CPU). You would need to have another version of Windows installed to be able to run an OS off of a high-level language like C#.

Assembly and C are two of the lowest level languages that any computer will understand because they relate directly to the BIOS/CPU. C# is a wrapper around lower-level languages and the Windows API.


-1: C#'s code is not recognized by Windows. C# code is compiled to Microsoft Intermediate Language (MSIL), which is later just-in-time compiled by the CLR to native machine instructions. Windows has nothing to do with it. - John Saunders
It runs on top of the .NET Framework; you must have the framework installed for your machine to be able to interpret the code. - amerninja13
How does that relate to my comment? - John Saunders
27