How to remove a lambda event handler

Possible Duplicates: Unsubscribe anonymous method in C# How do I Unregister 'anonymous' event handler I recently discovered that I can use lambdas to create simple event handlers. I could for example subscribe to a click event like this: button.Click += (s, e) => MessageBox.Show("Woho"); But how would you unsubscribe it? The C# specification explicitly states (IIRC) that if

如何删除一个lambda事件处理程序

可能重复: 在C#中取消订阅匿名方法 我如何取消注册'匿名'事件处理程序 我最近发现我可以使用lambda来创建简单的事件处理程序。 我可以例如订阅像这样的点击事件: button.Click += (s, e) => MessageBox.Show("Woho"); 但是,你会如何取消订阅? C#规范明确指出(IIRC)如果您有两个匿名函数(匿名方法或lambda表达式),它可能会或可能不会从该代码创建相同的委托。 (如果两个代表具有相同的目标并

LINQ's Distinct() on a particular property

I am playing with LINQ to learn about it, but I can't figure out how to use Distinct when I do not have a simple list (a simple list of integers is pretty easy to do, this is not the question). What I if want to use Distinct on a list of an Object on one or more properties of the object? Example: If an object is Person , with Property Id . How can I get all Person and use Distinct on them

LINQ在特定属性上的Distinct()

我正在玩LINQ来了解它,但是当我没有一个简单的列表(一个简单的整数列表很容易做,这不是问题)时,我无法弄清楚如何使用Distinct。 我如果想在对象的一个​​或多个属性上使用Distinct? 例如:如果一个对象是Person ,并带有Property Id 。 我如何获得所有人并使用对象的属性Id对他们使用Distinct ? Person1: Id=1, Name="Test1" Person2: Id=1, Name="Test1" Person3: Id=2, Name="Test2" 我怎样才能得到Person1和Perso

What is the correct way to create a single

Using C# and WPF under .NET (rather than Windows Forms or console), what is the correct way to create an application that can only be run as a single instance? I know it has something to do with some mythical thing called a mutex, rarely can I find someone that bothers to stop and explain what one of these are. The code needs to also inform the already-running instance that the user tried to

什么是创建单一的正确方法

在.NET(而不是Windows窗体或控制台)下使用C#和WPF,创建只能作为单个实例运行的应用程序的正确方法是什么? 我知道这与一些称为互斥体的神秘事物有关,我很少能找到一个能够阻止并解释其中之一的人。 代码还需要通知已经运行的实例,用户试图启动第二个实例,并且可能还会传递任何命令行参数(如果存在的话)。 这是一篇关于互斥解决方案的非常好的文章。 由于两个原因,文章描述的方法是有利的。 首先,它不需要依

Strategies for testing reactive, asynchronous code

I am developing a data-flow oriented domain-specific language. To simplify, let's just look at Operations. Operations have a number of named parameters and can be asked to compute their result using their current state. To decide when an Operation should produce a result, it gets a Decision that is sensitive to which parameter got a value from who. When this Decision decides that it is f

测试反应式异步代码的策略

我正在开发面向数据流的领域特定语言。 为了简化,让我们看看操作。 操作有许多命名参数,可以使用它们的当前状态要求计算其结果。 为了决定一个操作何时应该产生一个结果,它得到一个决定,该决定对哪个参数从谁得到一个值是敏感的。 当本决定决定完成时,它使用观察者发出一个信号。 访问者监听此信号,然后调用操作的结果方法,以便将其复用到其他操作的参数。 到目前为止,如此好的,很好地解耦设计,可组合和可重

Browser Emulator API for .NET

I'm looking for a good browser emulator API for .NET. I've been looking at WatiN, but I really don't need (want!) the GUI, I just want the HTML/DOM-parsing, JavaScript runtime and emulation of state, cache, and everything else. What I'm looking for would work something like this using (var browser = Browser.Create(BrowserType.Firefox)) { // Download all page resources and ex

用于.NET的浏览器模拟器API

我正在寻找一个适合.NET的浏览器模拟器API。 我一直在看WatiN,但我真的不需要(想要!)GUI,我只想HTML / DOM解析,JavaScript运行时和状态,缓存等模拟。 我正在寻找的东西就是这样的 using (var browser = Browser.Create(BrowserType.Firefox)) { // Download all page resources and executes JS var page = browser.Open("http://localhost:8080"); // Lookup <a id="nextButton" href="#" /> and trigge

How to mimic Picasa's rendering of reduced quality image to speed up drawing

I have an owner-drawn control where performance is an issue during quick repaints such as object drags, resizing and painting the selector square. i have noticed that several other apps, including Picasa , will temporarily draw a reduced-quality image during fast repaint scenarios and then update the image with a higher-quality version when the UI "settles down." How should I (can I?

如何模仿Picasa渲染质量降低的图像来加速绘制

我有一个所有者绘制的控件,其中性能是快速重绘期间的问题,如对象拖动,调整大小和绘制选择器正方形。 我注意到,包括Picasa在内的其他几个应用程序将在快速重绘场景中临时绘制质量较差的图像,然后在UI“安定下来”时使用更高质量的版本更新图像。 我应该如何(可以吗?)在发生许多快速重绘时产生质量较低的图像? 是否有其他类似的策略可以用来提高性能(或假的提高性能)。 额外信息: 这是一个类似于表单设计器的应

Efficient foreach child evaluation in parallel

I have a list of objects, each with a bool ShouldRun() method on them. I am currently iterating over the list of objects, and checking ShouldRun() on each object, and calling Run() on the first one to return true foreach (child in Children) { if (child.ShouldRun()) { child.Run(); break; } } I would like to do this in parallel, because evaluating shouldRun can take a dec

平行的有效的foreach儿童评估

我有一个对象列表,每个对象都有一个bool ShouldRun()方法。 我正在迭代对象列表,并在每个对象上检查ShouldRun(),并在第一个对象上调用Run()以返回true foreach (child in Children) { if (child.ShouldRun()) { child.Run(); break; } } 我想同时做到这一点,因为评估shouldRun可能需要相当长的时间,并且让后面的元素尽早开始评估是有好处的。 然而,我想不出一种能够满足这些条件的方法

How to post JSON to the server?

Here's the code I'm using: // create a request HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url); request.KeepAlive = false; request.ProtocolVersion = HttpVersion.Version10; request.Method = "POST"; // turn our request string into a byte stream byte[] postBytes = Encoding.UTF8.GetBytes(json); // this is important - make sure you specify type this way request.ContentType

如何发布JSON到服务器?

以下是我正在使用的代码: // create a request HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url); request.KeepAlive = false; request.ProtocolVersion = HttpVersion.Version10; request.Method = "POST"; // turn our request string into a byte stream byte[] postBytes = Encoding.UTF8.GetBytes(json); // this is important - make sure you specify type this way request.ContentType = "applic

Adding a directory temporarily to Windows 7's DLL search paths

I want to temporarily add a directory to the DLL search paths - is there a correct way to do this under Windows 7? Scenario I've got a C# application, let's call it WonderApp. WonderApp needs to call a C++ DLL, located in C:MyPath . So as part of WonderApp's Program.Main() , I added the following command: Environment.SetEnvironmentVariable("PATH", "C:\MyPath;" + Environment

临时将目录添加到Windows 7的DLL搜索路径

我想暂时添加一个目录到DLL搜索路径 - 在Windows 7下有没有正确的方法来做到这一点? 脚本 我有一个C#应用程序,我们称之为WonderApp。 WonderApp需要调用位于C:MyPath的C ++ DLL。 所以作为WonderApp的Program.Main() ,我添加了以下命令: Environment.SetEnvironmentVariable("PATH", "C:\MyPath;" + Environment.GetEnvironmentVariable("PATH")); 根据这篇文章,添加一个目录到PATH也应该将它添加到目录搜索DL

Is it possible to modify the content of HttpRequest POST in an IIS HttpModule?

I need to modify the content of certain HttpRequests (SSAS connection strings) in IIS. Basically, I need to add an element to the SOAP contained in the request. My approach so far has been to add a Filter to the HttpRequest, and perform the change in the filter's Read method. As far as I can tell, though, Read is never being executed. My understanding of the Request.Filter is that it ge

是否可以在IIS HttpModule中修改HttpRequest POST的内容?

我需要修改IIS中某些HttpRequests(SSAS连接字符串)的内容。 基本上,我需要向包含在请求中的SOAP添加一个元素。 到目前为止,我的方法是将过滤器添加到HttpRequest中,并在过滤器的Read方法中执行更改。 据我所知,虽然,Read永远不会被执行。 我对Request.Filter的理解是它从IIS处理请求时读取,所以IIS应该看到我的修改的请求。 是我正在尝试使用HttpModule实际上可能做到的,并且我的过滤器方法正确吗? 如果是这