将Windows服务作为控制台运行的最佳方法是什么?
我目前的想法是传入一个"/ exe"参数并执行Windows服务的工作,然后调用Application.Run().
我这样做的原因是为了更好地调试Windows服务并允许更容易地分析代码.该服务基本上托管.NET远程对象.
给定一个字符串,
string name = "Michael";
Run Code Online (Sandbox Code Playgroud)
我希望能够评估数组中哪个字符串最相似:
string[] names = new[] { "John", "Adam", "Paul", "Mike", "John-Michael" };
Run Code Online (Sandbox Code Playgroud)
我想为用户创建一条消息:"我们找不到'Michael',但'John-Michael'很接近.这就是你的意思吗?" 我该如何做出这个决定?
我有一个包装网格的用户控件.我希望能够设置底层网格的数据源,但是通过用户控件,如下所示:
<my:CustomGrid DataSource="{Binding Path=CollectionView}" />
Run Code Online (Sandbox Code Playgroud)
我在网格中设置了这样:
private static readonly DependencyProperty DataSourceProperty
= DependencyProperty.Register("DataSource", typeof(IEnumerable), typeof(CustomGrid));
public IEnumerable DataSource
{
get { return (IEnumerable)GetValue(DataSourceProperty); }
set
{
SetValue(DataSourceProperty, value);
underlyingGrid.DataSource = value;
}
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用(它也没有给我一个错误).永远不会设置数据源.我错过了什么?
我需要确定数据库中一组表的最大Id int值.该列始终为"Id"并且是主键.有没有一种简单的方法可以在不借助游标或循环的情况下做出这个决定?
如果我System.Drawing.Rectangle在画布和一个上有两个对象,计算哪个( 的任何部分,而不仅仅是它的)最接近那个Point的最佳方法是什么?RectangleRectangleLocation PointPoint
一个单元测试的例子:
Rectangle one = new Rectangle (0, 0, 10, 10);
Rectangle two = new Rectangle (20, 20, 10, 10);
Point point = new Point(14, 14);
Rectangle actual = ClosestToPoint(point, one, two);
// should be closer to one since one's bottom right is at (10, 10)
Assert.That(actual, Is.SameAs(one));
// method to write
public Rectangle ClosestToPoint(Point p, params Rectangle[] rectangles) { }
Run Code Online (Sandbox Code Playgroud) 我试图在NHibernate中使用"每个类层次结构表"策略在一个表中实现我的对象层次结构.我的NHibernate映射出错,可以通过一个简单的例子轻松复制.错误是:
System.NotSupportedException: Attempting to parse a null value into an sql string (column:activity0_.Type).
at NHibernate.SqlCommand.InFragment.ToFragmentString() in InFragment.cs: line 109
at NHibernate.Persister.Entity.SingleTableEntityPersister.DiscriminatorFilterFragment(String alias) in SingleTableEntityPersister.cs: line 551
Run Code Online (Sandbox Code Playgroud)
我可以使用以下域类重现这一点:
public interface IActivity
{
Guid Id { get; set; }
}
public abstract class Activity : IActivity
{
public DateTime StartTime { get; set; }
public Guid Id { get; set; }
}
public class Running : Activity
{
public string Where { get; set; }
}
public class Talking : Activity
{ …Run Code Online (Sandbox Code Playgroud) 我有一种情况,我不想太快地执行特定的功能.我目前有这个代码:
DoSomething();
Thread.Sleep(TimeSpan.FromMilliseconds(200));
Run Code Online (Sandbox Code Playgroud)
如何更改此代码以在函数时间或等待时间的最大值运行?
请注意:我无法使用系统时间,因为我的软件可以更改时钟时间.
因此,如果DoSomething()需要400 MS,它只会等待400 MS,但如果需要100 MS,程序将等待200 MS.
我需要使用一个数据结构来保存列表的最新X元素.一位同事给了我这个解决方案:
int start = 0;
const int latestElementsToKeep = 20;
int[] numbers = new int[latestElementsToKeep];
for (int i = 0; i < 30; i++)
{
numbers[start] = i;
if (start < numbers.Length - 1)
{
start++;
}
else
{
start = 0;
}
}
Run Code Online (Sandbox Code Playgroud)
所以在运行之后,数字数组的数字为19-29(最新的20个数字).
这很好,但在现实世界中很难使用它.有更简单的方法吗?
可以说我有两个容器:
<StackPanel>
<Label>First</Label>
</StackPanel>
<StackPanel>
<Label>Second</Label>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
而且我受这个对象的束缚:
public class Model
{
public bool ShowFirst { get; set; }
public bool ShowSecond { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
如何设置绑定以显示和隐藏相应的面板?
c# ×8
wpf ×2
.net ×1
algorithm ×1
arrays ×1
collections ×1
geometry ×1
nhibernate ×1
sql-server ×1
t-sql ×1