问题列表 - 第29193页

C#.NET 4.0 ConcurrentDictionary:一个锁中的TryRemove?

我相信这是有效的,我已经用多个并发线程测试了它(虽然对于竞争条件和死锁而言并非详尽无遗):

public static System.Collections.Concurrent.ConcurrentDictionary<string, item> dict =
        new System.Collections.Concurrent.ConcurrentDictionary<string, item>();
public static item dump;
Run Code Online (Sandbox Code Playgroud)

...

foreach (System.Collections.Generic.KeyValuePair<string, item> x in dict)
{
    lock (x.Value)
    {
        if (x.Value.IsCompleted)
        {
            dict.TryRemove(x.Key, out dump);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这个问题是这个问题的延续:

我可以从该字典的枚举循环中删除ConcurrentDictionary中的项吗?

这个问题:

更新ConcurrentDictionary中的值字段

在那我做两个"冒险"的演习:

  1. 从一段ConcurrentDictionary时间内删除值,同时枚举它(这似乎没问题).
  2. 锁定Value一部分ConcurrentDictionary.必要的是因为操纵值的字段不是线程安全的,只是操纵线程安全的值本身ConcurrentDictionary(上面的代码是一个更大的代码块的片段,其中实际操作值的字段).

c# multithreading locking .net-4.0

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

android:layout_weight如何工作?

当我有以下内容时,它显示顶部布局,四种颜色的面积比底部布局面积小得多.

根据此文档,当您添加更多内容时layout_weight,它应该增加区域,但在代码中会减少.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

  <LinearLayout
      android:orientation="horizontal"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="4">
      <TextView
          android:text="red"
          android:gravity="center_horizontal"
          android:background="#aa0000"
          android:layout_width="wrap_content"
          android:layout_height="fill_parent"
          android:layout_weight="3"/>
      <TextView
          android:text="green"
          android:gravity="center_horizontal"
          android:background="#00aa00"
          android:layout_width="wrap_content"
          android:layout_height="fill_parent"
          android:layout_weight="1"/>
      <TextView
          android:text="blue"
          android:gravity="center_horizontal"
          android:background="#0000aa"
          android:layout_width="wrap_content"
          android:layout_height="fill_parent"
          android:layout_weight="1"/>
      <TextView
          android:text="yellow"
          android:gravity="center_horizontal"
          android:background="#aaaa00"
          android:layout_width="wrap_content"
          android:layout_height="fill_parent"
          android:layout_weight="1"/>
  </LinearLayout>

  <LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1">
    <TextView
        android:text="row one"
        android:textSize="15pt"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>
    <TextView
        android:text="row two"
        android:textSize="15pt"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>
    <TextView
        android:text="row three"
        android:textSize="15pt"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>
    <TextView
        android:text="row four"
        android:textSize="15pt"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

android

36
推荐指数
5
解决办法
6万
查看次数

包含多个类的Java源代码应该是什么?

如果一个Java源文件中有多个类,那么.java文件的文件名是什么?

java

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

关于PLC指令的一个问题

当指令序列仍在处理时,输入X1是否会改变?

例如

LD X1
AND X2
OUT Y1

LD X1 // Can X1 loaded here differ from the previous one?
AND X3
OUT Y1
Run Code Online (Sandbox Code Playgroud)

谢谢

plc

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

事务在提交并且连接关闭后是否可以回滚?

事务在提交并且连接关闭后是否可以回滚?

    finally
    {
        // Commit the transaction.
        sqlTran.Commit();

        reader.Close();
        reader.Dispose();

        conn.Close();
        conn.Dispose();
    }
Run Code Online (Sandbox Code Playgroud)

我想给用户一个Opps选项!滚回去.所以如果它被提交可以回滚吗?

c# sql transactions sql-server-2005 visual-studio-2008

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

解决Clojure循环依赖关系

我的工作有不同的命名空间之间的一些循环依赖一些Clojure的代码,我试图找出解决这些问题的最佳途径.

  • 基本问题是我在其中一个文件中得到"No such var:namespace/functionname"错误
  • 我试图"声明"该函数,但后来抱怨:"不能引用不存在的合格var"
  • 我当然可以重构整个代码库,但是每次你有一个依赖关系来解决这个问题似乎都是不切实际的.....并且对于某些循环依赖的网络可能会变得非常难看
  • 我可以将一堆接口/协议/声明分离到一个单独的文件中,并且所有内容都引用了....但是这似乎最终会变得混乱并破坏我所拥有的相关功能的当前漂亮的模块化结构一起

有什么想法吗?在Clojure中处理这种循环依赖的最佳方法是什么?

clojure circular-dependency

15
推荐指数
3
解决办法
6669
查看次数

Visiblity作为XAML中的资源

为了简单起见,我想我可以在我的资源中添加一些设置并将其绑定到任何/我需要的时候.例如,我希望能够切换一些对象的可见性.所以我做了以下XAML:

// Namespaces....
xmlns:win="clr-namespace:System.Windows;assembly=System.Windows"
// Namespaces....
<UserControl.Resources>
    <win:Visibility x:Key="ReflectionVisibility" />
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)

虽然,现在我想知道我怎么能:

  • 在XAML中设置默认值

  • 更改后面代码中的值

谢谢!

c# silverlight xaml

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

Facebook Python-SDK VS. PyFacebook?

我开始使用Django开发一个facebook应用程序.

我正在尝试为我的应用程序选择合适的API包装器,我无法决定是否使用PyFacebook(文档很好但没有官方发布)或官方的Facebook Python SDK(令人惊讶地记录很少).

我失踪的两者之间是否存在重大差异?

谢谢你,利兹

python facebook pyfacebook

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

如何在红宝石中产生延迟

红宝石如何产生延迟?

我使用了睡眠声明,但它没有给我我想要的东西.

puts "amit"
sleep(10)
puts "scj"
Run Code Online (Sandbox Code Playgroud)

我希望它首先打印amit,然后延迟10秒,然后打印scj.

但在上面的情况下会发生什么,它会暂停10秒然后它将打印amit和scj在一起.我不希望这样.

我希望你得到我想说的话.

ruby

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

jQuery - 如何使这项工作(标记替换)

目前我有:

this.html(this.html().replace(/<\/?([i-z]+)[^>]*>/gi, function(match, tag) { 
            return (tag === 'p') ? match : '<p>';
            return (tag === '/p') ? match : '</p>';
            return (tag === 'script') ? match : 'script';
            return (tag === '/script') ? match : '/script';
        }));
Run Code Online (Sandbox Code Playgroud)

但是,<p><script>标签仍然被删除,我做错了什么?

html javascript jquery

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