小编Hel*_*ein的帖子

WPF:使用Dispatcher.BeginInvoke时访问绑定的ObservableCollection失败

我有以下内容:

public ICollectionView Children
{
 get
 {
  // Determining if the object has children may be time-consuming because of network timeouts.
  // Put that in a separate thread and only show the expander (+ sign) if and when children were found
  ThreadPool.QueueUserWorkItem(delegate 
  {
   if (_objectBase.HasChildren)
   {
    // We cannot add to a bound variable in a non-UI thread. Queue the add operation up in the UI dispatcher.
    // Only add if count is (still!) zero.
    Application.Current.Dispatcher.BeginInvoke(new Action(() =>
    {
     if …
Run Code Online (Sandbox Code Playgroud)

wpf multithreading dispatcher observablecollection threadpool

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

std :: wstring:与+连接无效

解决方案可能很明显,但我没有看到.我有这个简单的C++代码:

// Build the search pattern
// sPath is passed in as a parameter into this function
trim_right_if(sPath, is_any_of(L"\\"));
wstring sSearchPattern = sPath + L"\\*.*";
Run Code Online (Sandbox Code Playgroud)

我的问题是+运算符没有效果(在调试器中检查).该字符串sSearchPattern初始化为sPathonly 值.

注意:sPath是一个wstring.

我想要实现的例子:

sSearchPattern -> C:\SomePath\*.*

更多信息:

当我在调试器中查看sPath时,在最后一个字符后面看到两个NULL字符.当我查看sSearchPattern时,会附加"\*.*",但是在两个NULL字符之后.对此有何解释?

c++ string boost stl

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

为什么对 HKEY_CURRENT_USER 注册表配置单元的 32 位视图的访问会回退到 64 位视图?

我的 32 位应用程序在 64 位 Windows 7 上运行。我正在尝试访问注册表HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall。我可以在 regedit 中看到,Uninstall默认 64 位注册表视图中的项下方有几个子项(Dropbox 在该位置以及 Google Chrome 中创建了一个项)。Uninstall然而, 32位注册表视图中确实没有键。实际上,在regedit中只有Active Setup下面一个键HKEY_CURRENT_USER\Software\Wow6432Node\MicrosoftWindows下面连子键都没有Microsoft

但是,当我的 32 位应用程序尝试访问 的 32 位注册表视图时HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall,我从 64 位视图中获取密钥。这是为什么?

即使标志KEY_WOW64_32KEY在这里也无济于事。我们的代码需要知道结果是来自 32 位视图还是 64 位视图。

我们的代码还访问密钥的 32 位和 64 位视图HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall,但我在那里没有看到这个问题。不同之处在于 HKLM 的 32 位视图有密钥Uninstall,而 HKCU 的 32 位视图没有。

我知道WoW64的注册表重定向,但这似乎不同。我在 MSDN 上找不到任何有用的信息。有人可以解释一下吗?

windows registry wow64 visual-c++

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

为什么remove_if(...,lambda)表达式需要赋值运算符?

我有这个代码(简化):

std::vector<Session> sessions;
// ...
std::remove_if( sessions.begin(), sessions.end(), 
   [] (const Session& s) {
      return false;
   }
);
Run Code Online (Sandbox Code Playgroud)

当我编译它(在Visual Studio 2013 Update 1中)时,我收到以下错误:

algorithm(1759): error C2280: 'Session &Session::operator =(const Session &)' : attempting to reference a deleted function
   Session.h(78) : see declaration of 'Session::operator ='
Run Code Online (Sandbox Code Playgroud)

的确,我operator=Session课堂上删除了这样的内容:

Session& operator= (const Session& that) = delete;
Run Code Online (Sandbox Code Playgroud)

我的问题是:为什么remove_if使用lambda表达式需要赋值运算符?一个Session对象分配给另一个对象在哪里?

更新:正如@nosid和@Praetorian所解释的那样,remove_if需要移动或复制构造函数和赋值运算符.根据C++ 11标准,移动构造函数/赋值运算符应该由编译器自动生成.不幸的是Visual Studio 2013不这样做.由于类不可复制remove_if也无法求助于复制,因此编译器显示错误.我通过手动实现移动构造函数和移动赋值运算符来修复它.

c++ lambda stl operator-overloading c++11

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