如何在屏幕上获得当前的鼠标协调?我只知道Mouse.GetPosition()哪个获取了元素的mousePosition,但我想在不使用元素的情况下获得协调.
正如我在小应用程序中使用Sqlite所经历的那样,我总是使用sqliteadmin来使用其数据库清理功能来删除数据库中不必要的数据.
现在我想在我的应用程序中创建一个方法,其方式与sqliteadmin CleanUp相同 .
这该怎么做?
在此致谢谢
我想绑定到资源(DynamicResource)并访问该资源上的属性,但有没有办法做到这一点?
(我想在visual studio的xaml编辑器中可视化构造函数的默认值.当通过DataContext引用对象或通过我的Window类中添加的属性时,无法看到这些值...)
不工作xaml :( 在作曲家工作,但不在运行时...)
<Window ... >
<Window.Resources>
<local:MyClass x:Key="myResource" />
</Window.Resources>
<StackPanel>
<Button Content="{Binding Source={DynamicResource myResource} Path=Property1}" />
<Button Content="{Binding Source={DynamicResource myResource} Path=Property2}" />
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
与类(可能需要实现INotifyPropertyChanged):
public class MyClass
{
public MyClass()
{
this.Property1 = "Ok";
this.Property2 = "Cancel";
}
public string Property1 { get; set; }
public string Property2 { get; set; }
}
Run Code Online (Sandbox Code Playgroud) 我正在写一个像C#一样的函数:
public void CountNumber()
{
for(int i = 0; i < 40; i++) {
if(i > 20) {
goto out1;
}
Console.WriteLine("hello " + 1);
out1:
string hello = "";
}
}
Run Code Online (Sandbox Code Playgroud)
这基本上计算数字,如果i大于20,则不应写入console.writeline.它应该跳过并点击"out1"但是"out1"最终需要有一个函数来编译.它需要有"string hello ="""来编译.我不需要"string hello =""".我只是希望它什么也不做,并且循环结束了.如果没有out1:语句需要的"string hello =""",有没有办法做到这一点?喜欢:
public void CountNumber()
{
for(int i = 0; i < 40; i++) {
if(i > 20) {
goto out1;
}
Console.WriteLine("hello " + 1);
out1:
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
我尝试通过并行执行来优化代码,但有时只有一个线程承担所有重负载。下面的例子展示了如何在最多 4 个线程中执行 40 个任务,并且前十个任务比其他的更耗时。
Parallel.ForEach似乎将数组分成 4 部分,并让一个线程处理每个部分。所以整个执行过程大约需要 10 秒。它应该能够在最多 3.3 秒内完成!
有没有办法一直使用所有线程,因为在我的实际问题中不知道哪些任务耗时?
var array = System.Linq.Enumerable.Range(0, 40).ToArray();
System.Threading.Tasks.Parallel.ForEach(array, new System.Threading.Tasks.ParallelOptions() { MaxDegreeOfParallelism = 4, },
i =>
{
Console.WriteLine("Running index {0,3} : {1}", i, DateTime.Now.ToString("HH:mm:ss.fff"));
System.Threading.Thread.Sleep(i < 10 ? 1000 : 10);
});
Run Code Online (Sandbox Code Playgroud)