我的假设始终是CLR加载了应用程序域启动时所需的所有DLL.但是,我写了一个让我质疑这个假设的例子.我启动我的应用程序并检查加载了多少个模块.
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());
Run Code Online (Sandbox Code Playgroud)
然后我重复完全相同的代码,我的计数是不同的.附加DLL是C:\ WINNT\system32\version.dll.
我真的很困惑为什么计数会有所不同.
有人可以详细说明CLR正在做什么以及它如何加载这些东西,以及它正在做什么逻辑?
我正在阅读一本关于c#开发的一般书,我来到线程中止部分.
这本书说明了当你在另一个线程上调用Thread.Abort()时,该线程将抛出一个ThreadAbortException,即使你试图压制它,它也会自动重新抛出它,除非你做了一些通常不赞成的bs .这是提供的简单示例.
using System;
using System.Threading;
public class EntryPoint
{
private static void ThreadFunc()
{
ulong counter = 0;
while (true)
{
try
{
Console.WriteLine("{0}", counter++);
}
catch (ThreadAbortException)
{
// Attempt to swallow the exception and continue.
Console.WriteLine("Abort!");
}
}
}
static void Main()
{
try
{
Thread newThread = new Thread(new ThreadStart(EntryPoint.ThreadFunc));
newThread.Start();
Thread.Sleep(2000);
// Abort the thread.
newThread.Abort();
// Wait for thread to finish.
newThread.Join();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
Run Code Online (Sandbox Code Playgroud)
这本书说:
当您的线程完成处理中止异常时,运行时会在异常处理程序的末尾隐式重新抛出它.就像你自己重新抛出异常一样.因此,任何外部异常处理程序或finally块仍将正常执行.在该示例中,对Join的调用将不会像最初预期的那样永远等待. …
嘿我正在为excel互操作编写一个包装器,我希望能够在excel中打开一个csv文件并将其显示给用户.我已经掌握了基础知识,但是当我将可见设置为true并且excel显示时,所有列都被卡在第一列中,并且分隔逗号显示.
这是我的帮手.
public MyExcel(string filePath, bool readOnly)
{
_app = new Excel.Application();
_workbooks = _app.Workbooks;
_workbook = _workbooks.Open(_filepath, 0, _readOnly, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", !_readOnly, false, 0, true, true, true);
}
public void Show()
{
_app.Visible = true;
}
Run Code Online (Sandbox Code Playgroud)
有什么建议?
当我通过双击Excel打开文件时,正确处理所有内容.
我有一个HashSet.是否有一种方法可以利用IEqualityComparer检索传入一个对象的项目,该对象将满足IEqualityComparer中定义的equals方法?
这可以解释一下.
public class Program
{
public static void Main()
{
HashSet<Class1> set = new HashSet<Class1>(new Class1Comparer());
set.Add( new Class1() { MyProperty1PK = 1, MyProperty2 = 1});
set.Add( new Class1() { MyProperty1PK = 2, MyProperty2 = 2});
if (set.Contains(new Class1() { MyProperty1PK = 1 }))
Console.WriteLine("Contains the object");
//is there a better way of doing this, using the comparer?
// it clearly needs to use the comparer to determine if it's in the hash set.
Class1 variable = set.Where(e => …
Run Code Online (Sandbox Code Playgroud) 我正在迁移到 Reactive UI 版本 6,并尝试更完整地使用它提供的工具,即 ThrownExceptions。当我订阅抛出的异常属性时,什么也没有发生。我确信我错过了一些东西,只是不确定现在是什么。
在我的简化示例中,有一个带有绑定命令的按钮。
public ReactiveCommand<object> Delete { get; private set; }
public MainWindowViewModel()
{
Delete = ReactiveCommand.Create();
Delete.Subscribe(e => CommandExec());
Delete.ThrownExceptions.Subscribe(ex => HandleException(ex));
}
private object HandleException(Exception ex)
{
MessageBox.Show("Exception Handled");
return null;
}
public IObservable<object> CommandExec()
{
throw new Exception("throwing");
}
Run Code Online (Sandbox Code Playgroud)
我的假设是,当抛出异常时,我会看到一个“异常已处理”消息框。我确定我正在订阅某些内容,只是现在还不清楚它是什么。