MethodInvoker vs Action for Control.BeginInvoke

Which is more correct and why? Control.BeginInvoke(new Action(DoSomething), null); private void DoSomething() { MessageBox.Show("What a great post"); } or Control.BeginInvoke((MethodInvoker) delegate { MessageBox.Show("What a great post"); }); I kinda feel like I am doing the same thing, so when is the right time to use MethodInvoker vs Action , or even writing a lambda expression?

MethodInvoker vs Action for Control.BeginInvoke

哪个更正确,为什么? Control.BeginInvoke(new Action(DoSomething), null); private void DoSomething() { MessageBox.Show("What a great post"); } 要么 Control.BeginInvoke((MethodInvoker) delegate { MessageBox.Show("What a great post"); }); 我有点觉得我在做同样的事情,所以什么时候适合使用MethodInvoker vs Action ,甚至写一个lambda表达式? 编辑:我知道编写一个lambda与Action之间并没有什

Splitting on a Unique Character

I want to build a comma separated list so that I can split on the comma later to get an array of the values. However, the values may have comma's in them. In fact, they may have any normal keyboard character in them (they are supplied from a user). What is a good strategy for determining a character you are sure will not collide with the values? In case this matters in a language depende

分裂一个独特的人物

我想创建一个逗号分隔的列表,以便稍后可以分割逗号以获取值的数组。 但是,这些值可能包含逗号。 事实上,他们可能有任何正常的键盘字符(它们是由用户提供的)。 确定一个你确定角色的好策略是不会与这些值相冲突的? 在这种情况下,语言依赖的方式,我建立在C#中的“一些字符”分隔列表,并将其发送到浏览器被分割为JavaScript。 你可以用空字符分割它,并用双空字符来终止你的列表。 如果JavaScript正在使用该列表,为

Is accessing a variable in C# an atomic operation?

I've been raised to believe that if multiple threads can access a variable, then all reads from and writes to that variable must be protected by synchronization code, such as a "lock" statement, because the processor might switch to another thread halfway through a write. However, I was looking through System.Web.Security.Membership using Reflector and found code like this: publi

在C#中访问变量是一个原子操作吗?

我已经提出相信,如果多个线程可以访问一个变量,那么对该变量的所有读取和写入操作都必须由同步代码保护,例如“锁定”语句,因为处理器可能会在半途切换到另一个线程一个写。 但是,我使用Reflector查看System.Web.Security.Membership,发现如下代码: public static class Membership { private static bool s_Initialized = false; private static object s_lock = new object(); private static MembershipPro

Making a Scrollviewer fill the available space in a DockPanel

I somewhat of a WPF noob and am using a DockPanel to display the text content of an email in a TextBox in a ScrollViewer. The panel has a button bar and area for the email headers at the top, a button bar at the bottom, a panel at the right and the email itself should fill the remaining space dynamically: [Banner at top, below which is a button bar and box with email headers. At the bottom is

使滚动查看器填充DockPanel中的可用空间

我有点WPF noob,并且使用DockPanel在ScrollViewer的文本框中显示电子邮件的文本内容。 该面板有一个按钮栏和顶部的电子邮件标题区域,底部的按钮栏,右侧的面板以及电子邮件本身应该动态填充剩余空间: [顶部横幅,下面是一个按钮栏和带有电子邮件标题的框。 底部是另一个全宽按钮栏。 它们之间的空间分为右侧的固定宽度面板和电子邮件内容的大型文本框。] http://rowlandsoftware.com/Screenshots/LongEmail.png (Dock

WPF Container: equal width for elements but with spacing between them

I'd like to have a container with only four buttons in it. Buttons should be aligned horizontally, have the same width, not fill all the available space and have equal space between them. I would not like to set margin for buttons. Is there any combination of containers and/or their properties, that will help me to achieve this goal? I've tried using StackPanel, UniformGrid, simple

WPF容器:元素的宽度相等,但它们之间有间距

我想要一个只有四个按钮的容器。 按钮应水平对齐,具有相同的宽度,不能填充所有可用空间并且它们之间具有相等的空间。 我不想为按钮设置边距。 容器和/或其属性是否有任何组合,这将帮助我实现这一目标? 我试过使用StackPanel,UniformGrid,简单的网格,但没有成功 - 要么我得到巨大的按钮(虽然宽度相等),或者我最终与按钮之间的间距,但他们有不同的宽度。 将ItemsControl与某种面板结合使用似乎是对我来说最干净

dimensional array to an arbitrary degree?

Say I have a bool[][], and I want to rotate it by 37 degrees. I am aware that the transformation wouldn't always be perfect, and that's okay. I've ready plenty of answers on here similar to my question, but the only solutions I've found only solve the problem for 90 degree increments. The best way is to loop over the destination locations and for each of them read the correct

二维数组到任意的程度?

假设我有一个bool [] [],我想旋转它37度。 我知道转型并不总是完美的,没关系。 我已经在这里准备了很多类似于我的问题的答案,但我发现的唯一解决方案只能解决90度增量问题。 最好的方法是遍历目标位置,并为他们每个人阅读正确的源位置。 如果你尝试另一种方式(例如在源代码上循环并在目标文件上写),最终会产生差距。 旋转公式很简单... source_x = dest_x * c + dest_y * s + x0 source_y = dest_x * -s + dest_y

Performance surprise with "as" and nullable types

I'm just revising chapter 4 of C# in Depth which deals with nullable types, and I'm adding a section about using the "as" operator, which allows you to write: object o = ...; int? x = o as int?; if (x.HasValue) { ... // Use x.Value in here } I thought this was really neat, and that it could improve performance over the C# 1 equivalent, using "is" followed by a ca

“as”和可为空的类型带来惊喜

我只是修改了深入讨论可空类型的C#的第4章,并且添加了一个关于使用“as”运算符的部分,它允许您编写: object o = ...; int? x = o as int?; if (x.HasValue) { ... // Use x.Value in here } 我认为这非常简洁,并且它可以提高C#1等效性能,使用“is”后跟一个强制转换 - 毕竟,这样我们只需要一次动态类型检查,然后进行简单的值检查。 然而,这似乎并非如此。 我已经在下面包含了一个示例测试应用程序,它基本上将一

Visual Studio C# statement collapsing

When editing really long code blocks (which should definitely be refactored anyway, but that's beyond the scope of this question), I often long for the ability to collapse statement blocks like one can collapse function blocks. That is to say, it would be great if the minus icon appeared on the code outline for everything enclosed in braces. It seems to appear for functions, classes, region

Visual Studio C#语句崩溃

编辑真正长的代码块时(无论如何它都应该被重构,但这超出了这个问题的范围),我经常渴望能够折叠语句块,就像可以折叠功能块一样。 也就是说,如果代码大纲中包含在大括号中的所有内容都显示减号图标,那就太好了。 它似乎表现为函数,类,区域,名称空间,使用,但不适用于条件或迭代块。 如果我可以将诸如if,switch,foreach等类似的东西折叠起来,那将是太棒了! 谷歌搜索了一下,我发现显然VS中的C ++概述允许这个,

Can sigwaitinfo() wait for a super set of the process signal mask?

I'm tring to correctly emulate sigwait(), sigwaitinfo() and sigtimedwait() for Jehanne, but I can't grasp the expected behavior when multiple signals selected by the set argument are concurrently sent to a process waiting in one of these functions. For example, the first signal will cause the sigwaitinfo to return, filling the info argument. But what about the second signal? As far as

sigwaitinfo()可以等待超级进程信号掩码吗?

我正准备为Jehanne正确模拟sigwait(),sigwaitinfo()和sigtimedwait(),但是当set参数选择的多个信号同时发送到等待其中一个函数的进程时,我无法理解预期的行为。 例如,第一个信号将导致sigwaitinfo返回,填充info参数。 但第二个信号呢? 就我所见,如果第二个信号没有被阻塞(它不包含在过程信号掩码中),那么过程应该接收它,中断第一个信号管理,减少使用这些功能组的优势。 这让我想知道提供给这些函数的set

C Signal usage and process using IPC message queues

I have a program that uses a signal (SIGUSR2) for setup a catch handler function to process high priority incoming messages. The program receives incoming messages off an IPC message queue using msgrcv() in its main loop. When the sender of messages to the IPC message queue wants to notify the program that a high priority one is incoming, it sends SIGUSR2 to the process to have it stop process

C使用IPC消息队列的信号使用和处理

我有一个程序使用信号(SIGUSR2)来设置捕获处理函数来处理高优先级的传入消息。 该程序在其主循环中使用msgrcv()接收来自IPC消息队列的传入消息。 当发送给IPC消息队列的消息想要通知程序高优先级的消息传入时,它会向进程发送SIGUSR2以使其停止处理可能正在处理的任何当前消息。 在信号捕捉处理函数中,我首先进入: 信号(SIGUSR2,SIG_IGN); 忽略任何发生抢先的新信号。 那么代码会处理抢占请求,在该请求中它