clr

Asynchronous iterator Task<IEnumerable<T>>

烂漫一生 提交于 2019-11-27 09:01:13
I’m trying to implement an asynchronous function that returns an iterator. The idea is the following: private async Task<IEnumerable<char>> TestAsync(string testString) { foreach (char c in testString.ToCharArray()) { // do other work yield return c; } } However, there is an error message that the function cannot be an iterator block because Task<IEnumerable<char>> is not an iterator interface type. Is there a solution? Joe Amenta It sounds like what you may really be looking for is something like IObservable<T> , which is sort of like a push-based asynchronous IEnumerable<T> . See Reactive

Is it possible to get parameters' values for each frame in call stack in .NET

跟風遠走 提交于 2019-11-27 08:56:59
I'm talking about managed .NET code. If we run any program and attach VS to it we can see parameters' values for each method in call stack. I'd like to create a logging solution which will log all parameters' values for each method in call stack. Actually I need this info in case an exception occurs. I know it's possible with profiling API. But I wonder is it possible with only managed code? UPDATE: Ok, probably with pure .NET it's impossible. Then may be with some kind of unmanaged code... the point is to do this from within application itself. An application in case of an exception could

What can you do in MSIL that you cannot do in C# or VB.NET? [closed]

江枫思渺然 提交于 2019-11-27 08:55:13
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . All code written in .NET languages compiles to MSIL, but are there specific tasks / operations that you can do only using MSIL

How are arrays created and accessed

余生长醉 提交于 2019-11-27 08:33:27
问题 I understand(not completely why, though) that instances of primitive types such as int, float are stored on the stack and are not heap allocated. But I am a bit confused about how arrays of primitive types are stored and accessed. I have this question because System.Array is a reference type. And reference types are heap allocated. int[] integers = {1,2,3,4,5}; How are these individual integers stored and accessed on the memory? 回答1: Your "understanding" is flawed, basically. Value type

How does CorFlags.exe /32BIT+ work?

こ雲淡風輕ζ 提交于 2019-11-27 08:07:44
I guess my question is about the CLR Loader. I want to understand the mechanics behind CorFlags.exe /32BIT+ functionality. We know that when one starts an assembly compiled with the Any CPU flag set on 64-bit Windows, it starts as a 64-bit process. If one run CorFlags /32BIT+ on that assembly, it will start as a 32-bit process. I think this is a fascinating feature. I have so many questions about it: How is it implemented? Does the OS Loader get involved? Is possible to build a custom application (I guess an unmanaged one) that loads 32-bit or 64-bit CLR at a wish? Is there an article, book,

Unload event for the default Application Domain?

旧时模样 提交于 2019-11-27 07:23:06
问题 Is there an Unload event, or any event, notification, message, mechanism, or hook, that i can use to be notified before the "default" application domain is unloaded? i have code that needs to know when the application domain (almost always the default domain) is ending. Note: i don't know what kind of application a developer will be creating when he uses my code. It could be: a console application a WinForms application an ASP.net application an ASP.net web-site Runtime Callable Wrapper (RCW)

How are DLLs loaded by the CLR?

无人久伴 提交于 2019-11-27 07:19:53
My assumption was always that the CLR loaded all of the DLLs it needed on startup of the app domain. However, I've written an example that makes me question this assumption. I start up my application and check to see how many modules are loaded. Process[] ObjModulesList; ProcessModuleCollection ObjModulesOrig; //Get all modules inside the process ObjModulesList = Process.GetProcessesByName("MyProcessName"); // Populate the module collection. ObjModulesOrig = ObjModulesList[0].Modules; Console.WriteLine(ObjModulesOrig.Count.ToString()); I then repeate the exact same code and my count is

Is there a way to get the string representation of HRESULT value using win API?

喜你入骨 提交于 2019-11-27 07:03:13
Is there a function in win API which can be used to extract the string representation of HRESULT value? The problem is that not all return values are documented in MSDN, for example ExecuteInDefaultAppDomain() function is not documented to return "0x80070002 - The system cannot find the file specified.", however, it does! Therefore, I was wondering whether there is a function to be used in common case. eran You can use _com_error : _com_error err(hr); LPCTSTR errMsg = err.ErrorMessage(); If you don't want to use _com_error for whatever reason, you can still take a look at its source, and see

In a switch vs dictionary for a value of Func, which is faster and why?

这一生的挚爱 提交于 2019-11-27 06:57:39
Suppose there is the following code: private static int DoSwitch(string arg) { switch (arg) { case "a": return 0; case "b": return 1; case "c": return 2; case "d": return 3; } return -1; } private static Dictionary<string, Func<int>> dict = new Dictionary<string, Func<int>> { {"a", () => 0 }, {"b", () => 1 }, {"c", () => 2 }, {"d", () => 3 }, }; private static int DoDictionary(string arg) { return dict[arg](); } By iterating over both methods and comparing, I am getting that the dictionary is slightly faster, even when "a", "b", "c", "d" is expanded to include more keys. Why is this so? Does

Is CLR loaded and initialized everytime,when a new managed application is loaded?

橙三吉。 提交于 2019-11-27 06:56:31
问题 Is CLR loaded and initialized everytime, when a new managed application is loaded and there is a managed application already present? e.g. If on my machine, application "TestApp" is running and after that I start another application "DemoApp". In this case, wiill CLR be loaded again for DemoApp? Or it will use the same one which is loaded by TestApp? 回答1: Yes, and assemblies are JIT compiled, heaps are allocated and so forth. The Windows image loader will help a bit but in general the CLR