小编The*_*ner的帖子

C#WPF:滑块移动到准确位置

我在WPF窗口中使用了一个滑块,当用户点击滑块轨道上的某个位置时,我想要那个拇指转到那个确切的位置.目前,当我点击某处,拇指朝去那个位置,但不完全相同那个位置.我怎样才能实现我的目标?

编辑:一个更好地解释我想要的例子:如果拇指位于10并且我在100附近按下鼠标,我希望它跳到100(不通过其他值).

c# wpf user-interface user-controls slider

15
推荐指数
2
解决办法
8540
查看次数

获得CPU频率需要一些帮助

我正在尝试制作一个C#软件来读取有关CPU的信息并将其显示给用户(就像CPU-Z一样).我目前的问题是我找不到显示CPU频率的方法.

起初我尝试使用Win32_Processor类的简单方法.事实证明它非常有效,除非CPU超频(或低频).

然后,我发现我的注册表在 HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor\0中包含CPU的"标准"时钟(即使超频).问题是在现代CPU中,当CPU不需要它的全功率时,核心乘法器正在减少,因此CPU频率也在变化,但是注册表中的值保持不变.

我的下一步是尝试使用RdTSC来实际计算CPU频率.我使用C++是因为如果方法正常,我可以将它嵌入到C#项目中.我在http://www.codeproject.com/Articles/7340/Get-the-Processor-Speed-in-two-simple-ways找到了下一个代码, 但问题是一样的:程序只给出了我的最大频率(比如在注册表值,1-2 Mhz的差异),它看起来像它加载CPU超过它应该(我甚至有CPU负载峰值).

#include "stdafx.h"
#include <windows.h>
#include <cstdlib>
#include "intrin.h"
#include <WinError.h>
#include <winnt.h>

float ProcSpeedCalc() {

#define RdTSC __asm _emit 0x0f __asm _emit 0x31

    // variables for the clock-cycles:
    __int64 cyclesStart = 0, cyclesStop = 0;
    // variables for the High-Res Preformance Counter:
    unsigned __int64 nCtr = 0, nFreq = 0, nCtrStop = 0;

    // retrieve performance-counter frequency per second:
    if(!QueryPerformanceFrequency((LARGE_INTEGER *) &nFreq))
        return 0;

    // retrieve …
Run Code Online (Sandbox Code Playgroud)

c# c++ visual-c++

5
推荐指数
1
解决办法
2964
查看次数

多线程的巨大内存和CPU使用率

我正在尝试创建一个具有播放列表选项的媒体播放器.当一个负载10-20首歌没有问题.所以我尝试了更苛刻的东西:我试着加载2048首歌曲(我拍了好几首歌并复制了很多次).试图将它们加载到我的媒体播放器中,我的CPU和Ram内存增长了95%以上(只加载了前250首歌曲),有一次我的电脑重启了.所以我试图通过使用不让应用程序接管计算机的东西来减慢操作:如果CPU负载超过85%并且内存负载超过90%(我使用64位),我会停止加载新歌曲操作系统与Windows 8,如果这很重要).它在某种程度上起作用,允许我加载近600首歌曲然后:

A first chance exception of type 'System.InvalidOperationException' occurred in mscorlib.dll
A first chance exception of type 'System.InvalidOperationException' occurred in mscorlib.dll
A first chance exception of type 'System.InvalidOperationException' occurred in mscorlib.dll
A first chance exception of type 'System.InvalidOperationException' occurred in mscorlib.dll
A first chance exception of type 'System.InvalidOperationException' occurred in mscorlib.dll
The thread 'vshost.NotifyLoad' (0x1d0c) has exited with code 0 (0x0).
The thread 'vshost.LoadReference' (0x1e48) has exited with code 0 (0x0).
A first chance exception of type 'System.OutOfMemoryException' occurred …
Run Code Online (Sandbox Code Playgroud)

c# multithreading memory-management media-player threadpool

1
推荐指数
1
解决办法
2110
查看次数

Windows应用商店CurrentApp.LoadListingInformationAsync() - 错误0x801900cc

我在商店中有一个Windows 8.1应用程序,但是当我尝试使用下一段代码添加到我的应用程序中的新功能时

var listingInfo = await CurrentApp.LoadListingInformationAsync();
Run Code Online (Sandbox Code Playgroud)

我收到一个错误,我不知道这意味着什么.我确实抓住了错误,然后我在MessageDialog上显示了它,然后我拿了一个打印屏幕.这是错误:

We could not receive your donation due to an unexpected error:
System.Exception: Exception from HRESULT: 0x801900CC
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task)
    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
    at ArchMedia_Player.Services.Donations.<ListingInformationAsync> d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task)
    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
    at ArchMedia_Player.Services.Donations.<Donate>d__a.MoveNext()
Run Code Online (Sandbox Code Playgroud)

有谁知道这意味着什么,我该如何解决?我还提到这完全正常:(使用CurrentApp 模拟器)

var listingInfo = await CurrentAppSimulator.LoadListingInformationAsync();
Run Code Online (Sandbox Code Playgroud)

c# windows visual-studio windows-store windows-store-apps

1
推荐指数
1
解决办法
1359
查看次数