使用#if (DEBUG)和System.Diagnostics.Debugger.IsAttached在visual studio中有什么不同?是否有DEBUG设置标志但没有附加调试器的情况,或者在DEBUG未设置标志时可以附加调试器的情况?
在html中,没有什么可以阻止你创建自定义属性,因为它实际上是xml,如
<span myProperty="myValue"></span>
Run Code Online (Sandbox Code Playgroud)
然后你可以通过javascript阅读该属性.
你能在wpf做同样的事情吗?例如:
<Canvas MyProperty="MyValue" Name="MyCanvas" DataContext="{Binding}" Background="Black" Margin="181,0,0,0"></Canvas>
Run Code Online (Sandbox Code Playgroud)
如果是这样,您将如何访问该属性?例如:
MyCanvas.MyProperty;
Run Code Online (Sandbox Code Playgroud) 我终于得到了VS2012并得到了一个简单的演示并且正在努力检查异步的潜在性能提升并等待,但令我沮丧的是它更慢!它可能我做错了,但也许你可以帮助我.(我还添加了一个简单的Threaded解决方案,并且按预期运行得更快)
我的代码使用一个类来根据系统中的内核数量对数组求和(-1)我有4个内核,所以我看到了大约2倍的加速(2.5个线程)用于线程,但是减少了2倍的速度同样的事情,但使用async/await.
代码:(注意,您需要添加引用以System.Management使核心检测器工作)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Management;
using System.Diagnostics;
namespace AsyncSum
{
class Program
{
static string Results = "";
static void Main(string[] args)
{
Task t = Run();
t.Wait();
Console.WriteLine(Results);
Console.ReadKey();
}
static async Task Run()
{
Random random = new Random();
int[] huge = new int[1000000];
for (int i = 0; i < huge.Length; i++)
{
huge[i] = random.Next(2);
}
ArraySum summer = new ArraySum(huge);
Stopwatch …Run Code Online (Sandbox Code Playgroud) 好的,在Windows窗体中,您可以使用它.refresh()来在元素上生成重绘事件.WPF中是否有类似的解决方案?
解释我正在做什么,我在画布对象上绘制一个迷宫,并希望看到迷宫被绘制(所以我可以看到进展),而不是等待28分钟突然出现的解决方案.我在画布上用一系列Rectangles 绘制块.刷新应该在矩形还是画布上?
这是最近的输出:http: //imgur.com/ftFOv
如果有可能,我想在c#中找到解决方案.谢谢.
我正在网格中绘制一些图像.图像保存为16x16px pngs.
但是,我后来决定将网格的大小增加到32x32px.
当我使用以下代码时:
graphics.DrawImage(image, Xdraw, Ydraw, 32, 32);
Run Code Online (Sandbox Code Playgroud)
其中image是从png加载的Image,而Xdraw和Ydraw是在左上角决定的.
图像稍微模糊,因为.DrawImage使用双三次(或其他一些平滑函数)来放大图像.我希望它关闭平滑,所以我可以保留硬边.
这可能吗?
所以,我使用了winForms .CreateGraphics来绘制各种不同的东西,从线条到盒子再到图像.它非常活泼,反应灵敏.
我想在C#中学习WPF
我发现WPF允许我将"矩形"对象"添加"到画布上,以便正确显示它们.但是,我有时会画出数十万个矩形,并且绘制速度会变得非常慢,当我移动一个矩形时,UI变得不那么活泼.
在winForms中直接绘制到元素上并不是很快,但无论我绘制多少,它都是一致的.
在WPF中有这样的解决方案吗?
我尝试添加一个linq System.Drawing,它给了我一个Graphics对象,但我试过的wpf元素都没有这个.CreateGraphics()方法.
问题
我从c#调用powershell命令但是,PowerShell命令对象似乎只有属性bool HasErrors不能帮助我知道我收到了什么错误.
这就是我构建powershell命令的方法
图书馆
public static class PowerSheller
{
public static Runspace MakeRunspace()
{
InitialSessionState session = InitialSessionState.CreateDefault();
Runspace runspace = RunspaceFactory.CreateRunspace(session);
runspace.Open();
return runspace;
}
public static PowerShell MakePowershell(Runspace runspace)
{
PowerShell command = PowerShell.Create();
command.Runspace = runspace;
return command;
}
}
Run Code Online (Sandbox Code Playgroud)
调用Move-Vm cmdlet
using (Runspace runspace = PowerSheller.MakeRunspace())
{
using (PowerShell command = PowerSheller.MakePowershell(runspace))
{
command.AddCommand("Move-VM");
command.AddParameter("Name", arguments.VMName);
command.AddParameter("ComputerName", arguments.HostName);
command.AddParameter("DestinationHost", arguments.DestinationHostName);
if (arguments.MigrateStorage)
{
command.AddParameter("IncludeStorage");
command.AddParameter("DestinationStoragePath", arguments.DestinationStoragePath);
}
try
{ …Run Code Online (Sandbox Code Playgroud) 我意识到标题有点奇怪.但这是一个我想弄清楚的统计问题,但我很难过.(不,不,它不是功课,看到底部的真实解释)
前提很简单.你有N桶.每个水桶都可以容纳H球.没有一个桶是满的.你已经把D球放在水桶里了,但是你不知道球在哪里(你忘记了!)你随机选择一个水桶来增加一个球.那个桶满载的概率是多少.
一些示例可能的图表,其中N = 4,H = 3,D = 4.每种情况只是球的假设排列.对于许多情况之一.
Scenario 1: 1 bucket could be filled.
| | | | |
+ - + - + - + - +
| B | | | |
+ - + - + - + - +
| B | B | | B |
+ - + - + - + - +
Scenario 2: 2 buckets could be filled.
| | | | |
+ - + - + - …Run Code Online (Sandbox Code Playgroud) 我正在尝试在没有 jQuery 的情况下学习一些东西。这是我面临的挑战之一。
我有一个固定的contenteditable div,当向 div 添加文本时,如果scrollHeight超过clientHeight我缩小字体,直到内容适合 div。
有时我会“重建”以innerHTML编程方式替换文本的文本。或者用户可以删除应该减少 的文本scrollHeight,但在这两种情况下,scrollHeight仍然是最大值。我需要一些方法来增加字体大小以再次“适合”div。(理想情况下不是超级贵)
例子:
我的clientHeight=142,和scrollHeight=158。一个循环减小字体大小,直到scrollHeight142。然后,用户删除一行文本,但scrollHeight仍然是142,没有变化。
减少/增加高度的代码:
var textBox = document.getElementById('text');
var current, min = 6, max = 14;
current = textBox.style.fontSize.substr(0, textBox.style.fontSize.length - 2);
current = parseInt(current);
if (textBox.clientHeight < textBox.scrollHeight) {
while (textBox.clientHeight < textBox.scrollHeight) {
current--;
if (current < min) break;
textBox.style.fontSize = '' + current + 'pt';
}
} …Run Code Online (Sandbox Code Playgroud) C# 允许您为枚举元素赋值,例如
public enum Animals
{
Dog = 0, Cat = 1,
}
Run Code Online (Sandbox Code Playgroud)
你也可以像这样从他们那里投射。
public void demo()
{
int dog = (int)Animals.Dog;
Animals cat = (Animals)(dog++);
}
Run Code Online (Sandbox Code Playgroud)
但是 c# 也可以让你做这样的事情
public enum Animals
{
Dog = Vector2.One, Cat = Vector2.Zero,
}
Run Code Online (Sandbox Code Playgroud)
但是,您无法通过演员表将 Vector2 重新放入和取出。如
Vector2 dog = (Vector2)Animals.Dog; //this fails
Run Code Online (Sandbox Code Playgroud)
这个问题可以解决吗?*NoteVector2是一个类对象,Vector2.One并且Vector2.Zero是此类对象的静态声明。这意味着 Dog 被分配给一个内存引用。
我正在实现一个反馈对话框,并希望使用IScorableand键将“ feedback”一词从任何地方插入该对话框并将其压入FeedbackDialog堆栈。
从用户收集反馈时,我不希望出现这种情况。有没有办法确定my FeedbackDialog是否已经在堆栈中?所以我不会不小心双按它吗?
c# ×8
wpf ×3
.net ×2
graphics ×2
.net-4.5 ×1
algorithm ×1
async-await ×1
botframework ×1
casting ×1
enums ×1
equivalent ×1
image ×1
javascript ×1
math ×1
performance ×1
powershell ×1
probability ×1
properties ×1
redraw ×1
resize ×1
statistics ×1
user-input ×1
wpf-controls ×1
xaml ×1
xna ×1