小编Sea*_*man的帖子

使用jQuery隐藏pageLoad()上的元素

如果我使用jquery在page_load上隐藏了一些元素,那么当页面发布然后消失时,元素会瞬间闪烁:

  function pageLoad() {

        $('#panelOne').hide();
        $('#panelTwo').hide();
Run Code Online (Sandbox Code Playgroud)

有没有办法防止闪烁?

我不想将元素css设置为visibility:hidden,因为稍后调用jquery .show()方法似乎不显示元素.

javascript css jquery

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

计算函数/蒙特卡罗方法合理性的算法

我正在编写一个试图复制本文开头讨论的算法的程序,

http://www-stat.stanford.edu/~cgates/PERSI/papers/MCMCRev.pdf

F是从char到char的函数.假设P1(f)是该函数的"合理性"度量.算法是:

从对函数的初步猜测开始,比如f,然后是新的函数f* -

  • 计算Pl(f).
  • 通过对值f进行随机转置来更改为f*,将其分配给两个符号.
  • 计算Pl(f*); 如果这大于P1(f),则接受f*.
  • 如果没有,翻转一个Pl(f)/ Pl(f*)硬币; 如果它出现在头上,接受f*.
  • 如果硬币抛出尾巴,请留在f.

我正在使用以下代码实现此功能.我正在使用c#,但试图让每个人都更加简化.如果有更好的论坛,请告诉我.

 var current_f = Initial();    // current accepted function f
 var current_Pl_f = InitialPl();  // current plausibility of accepted function f

 for (int i = 0; i < 10000; i++)
        {
            var candidate_f = Transpose(current_f); // create a candidate function

            var candidate_Pl_f = ComputePl(candidate_f);  // compute its plausibility

            if (candidate_Pl_f > current_Pl_f)            // candidate Pl has improved
            {
                current_f = candidate_f;            // accept the candidate
                current_Pl_f = …
Run Code Online (Sandbox Code Playgroud)

c# algorithm functional-programming markov-chains montecarlo

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

同时从远程服务下载JSON数据

我在客户端和服务器端点上使用WCF服务通过HTTP同时从多个远程服务器提取JSON数据.我注意到,对于每个连续的异步启动请求,http请求所花费的时间通常会增加,即使数据量不一定增加.换句话说,如果我启动12个线程池线程(使用Func <>.BeginInvoke),那么每个请求在被定时后,将在我的日志中显示如下:

  :HttpRequest invoked. Elapsed: 325ms
  :HttpRequest invoked. Elapsed: 27437ms
  :HttpRequest invoked. Elapsed: 28642ms
  :HttpRequest invoked. Elapsed: 28496ms
  :HttpRequest invoked. Elapsed: 32544ms
  :HttpRequest invoked. Elapsed: 38073ms
  :HttpRequest invoked. Elapsed: 41231ms
  :HttpRequest invoked. Elapsed: 47914ms
  :HttpRequest invoked. Elapsed: 45570ms
  :HttpRequest invoked. Elapsed: 61602ms
  :HttpRequest invoked. Elapsed: 53567ms
  :HttpRequest invoked. Elapsed: 79081ms
Run Code Online (Sandbox Code Playgroud)

这个过程非常简单.我只是在循环中启动每个请求,然后在使用合并数据之前对所有操作调用.WaitAll().

看起来Http请求占用的时间比使用少量数据时要长.实际上,小数据量和大量数据之间的差异总体上看起来很小.这种瓶颈是由于并发的http请求必须共享带宽,还是存在线程/上下文切换问题?只是想指向正确的方向.

编辑 - 为了清楚起见,我同步运行相同的过程,结果如下:

  :HttpRequest invoked. Elapsed: 20627ms
  :HttpRequest invoked. Elapsed: 16288ms
  :HttpRequest invoked. Elapsed: 2273ms
  :HttpRequest invoked. Elapsed: 4578ms
  :HttpRequest invoked. Elapsed: 1920ms
  :HttpRequest invoked. Elapsed: …
Run Code Online (Sandbox Code Playgroud)

c# optimization wcf multithreading json

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

比较两个Dictionary <T>的最佳方法是否相等

这是为两个词典的相等性创建比较器的最佳方法吗?这需要准确.请注意,Entity.Columns是KeyValuePair的字典(字符串,对象):

public class EntityColumnCompare : IEqualityComparer<Entity>
{
    public bool Equals(Entity a, Entity b)
    {
        var aCol = a.Columns.OrderBy(KeyValuePair => KeyValuePair.Key);
        var bCol = b.Columns.OrderBy(KeyValuePAir => KeyValuePAir.Key); 

        if (aCol.SequenceEqual(bCol))
            return true;
        else
            return false;           
    }

    public int GetHashCode(Entity obj)
    {
        return obj.Columns.GetHashCode(); 
    }
}
Run Code Online (Sandbox Code Playgroud)

对GetHashCode实现也不太确定.

谢谢!

c# generics collections dictionary iequalitycomparer

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

WCF消息安全性是否实际加密了消息内容?

我已阅读MSDN上提供的文档以及本网站上的其他一些帖子.但是,当使用带有证书的消息安全性时,WCF(特别是NetTcpBinding)是否会实际加密消息内容仍然有点不清楚.有人有确切消息么?

例如,您可以在配置中指定传输和消息凭据:

       <security mode="TransportWithMessageCredential">
          <transport clientCredentialType="Certificate"/>
          <message clientCredentialType="Certificate"
                   negotiateServiceCredential="true" />
       </security>
Run Code Online (Sandbox Code Playgroud)

据我所知,MSDN文档暗示消息安全性仅依赖于用户名/密码或基于证书的身份验证(协商),但没有具体说明消息本身实际上是在消息级别加密的.

例如,如果我只使用消息安全性,基于证书的协商,我不认为消息内容实际上是加密的(即,数据包嗅探器可以拦截原始消息内容 - 即使服务强制执行身份验证)?

如果可以进行真正的消息级加密(使用NetTcpBinding),如何在代码中完成?我相信这与AlgorithmSuite有关,虽然我不确定,

binding.Security.Mode = SecurityMode.Message;
binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
binding.Security.Message.AlgorithmSuite = new System.ServiceModel.Security.TripleDesSecurityAlgorithmSuite(); 
Run Code Online (Sandbox Code Playgroud)

c# security wcf certificate nettcpbinding

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

XML SChema中的集合

学习XML Schema,我希望能够在另一个元素中包含元素集合.看起来很简单,但不太确定如何做到这一点.

这是架构:

 <xs:attributeGroup name="ProcedureMappingFragment">
  <xs:attribute name="ParameterName" type="xs:string" />
  <xs:attribute name="TypeName" type="xs:string" />
  <xs:attribute name="PropertyName" type="xs:string" />
Run Code Online (Sandbox Code Playgroud)

<xs:complexType name="ProcedureMappingSection">
  <xs:sequence>
    <xs:element name="ProcMapping" type="ProcedureMapping" /> 
  </xs:sequence>
</xs:complexType>

<xs:complexType name="ProcedureMapping">
  <xs:attributeGroup id="two" ref="ProcedureMappingFragment" />
    <xs:attribute name="ProcedureName" type="xs:string" />
</xs:complexType>
Run Code Online (Sandbox Code Playgroud)

而我正试图产生这样的东西:

<MappingSection xmlns="http://tempuri.org/ServiceMapping.xsd">
  <ProcMapping ParameterName="ParameterName1" TypeName="TypeName1" PropertyName="PropertyName1" ProcedureName="ProcedureName1" />
  <ProcMapping ParameterName="ParameterName1" TypeName="TypeName1" PropertyName="PropertyName1" ProcedureName="ProcedureName1" />
  <ProcMapping ParameterName="ParameterName1" TypeName="TypeName1" PropertyName="PropertyName1" ProcedureName="ProcedureName1" />
  <ProcMapping ParameterName="ParameterName1" TypeName="TypeName1" PropertyName="PropertyName1" ProcedureName="ProcedureName1" />
</MappingSection>
Run Code Online (Sandbox Code Playgroud)

但是它告诉我,我只能在MappingSection中有一个ProcMapping.具体来说,它调用第二个ProcMapping元素对于命名空间MappingSection无效.

xml xsd

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

jQuery slideToggle()性能不佳和/或冻结IE8

我在IE8中使用.slideToggle jQuery函数表现不佳.它要么波动,要么完全冻结浏览器.在firefox chrome opera等中运行得很好

我认为它可能与我的DOCTYPE属性有关?我不确定.但是,我尝试了很多本网站及其他网站提到的解决方案,但到目前为止还没有一个解决方案,包括确保没有任何滑动元素设置为position:relative.

这是脚本和HTML.基本上,当用户单击上部div中包含的单选按钮上的按钮时,上部div会折叠,而下部div会打开更多按钮.它们最初被隐藏,因此检查.css('display'):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 function btnList_Type_Click() {

    $('#btnList_Type_Div').slideToggle(200, null);

    if ($("#btnPanelTwo").css('display') == 'none') {

        $('#btnPanelTwo').slideToggle(200, null);
    }

    if ($("#btnList_Date_Div").css('display') == 'none') {

        $('#btnList_Date_Div').slideToggle(200, null); 
    } 
}


     <div id="btnPanelTwo" class="lightPanel" onmouseover="page.cursor('pointer')" onmouseout="page.cursor('default')"  
     style="height: 36px; width:320px; margin-left:20px; margin-top:0px; display:none;">
    <span style="font-size: 13pt; left: 14px; top:10px;">Step 2: &nbsp&nbsp Choose Date Range:</span>
    </div>
    <div id="btnList_Date_Div" style="margin-left:60px; width:320px; height:325px; display:none;">
    <asp:RadioButtonList 
         ID="btnList_Date" runat="server" style="margin-left: 35px; margin-top:12px;" 
         Width="226px" AutoPostBack="False" Font-Size="11pt"              
     </asp:RadioButtonList>
      <asp:TextBox ID="txt_StartRange" class="textbox" runat="server" style="margin-left: …
Run Code Online (Sandbox Code Playgroud)

javascript performance jquery internet-explorer-8 slidetoggle

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

确定 .NET 类型的序列化大小和非托管内存效率

我的问题是是否可以确定引用类型的序列化大小(以字节为单位)。

情况如下:

我使用 BinaryFormatter 类来序列化基本 .NET 类型,例如:

[Serializable]
public class Foo
{
    public string Foo1 { get; set; }
    public string Foo2 { get; set; } 
}
Run Code Online (Sandbox Code Playgroud)

我将每个项目序列化为 byte[],然后将该段添加到现有 byte[] 的末尾,并在每个段的末尾添加回车符以分隔对象。

为了反序列化,我使用 Marshal.ReadByte() 如下:

List<byte> buffer = new List<byte>();

for (int i = 0; i < MapSize; i++)
{
    byte b = Marshal.ReadByte(readPtr , i); 

    if (b != delim)  // read until encounter a carriage return 
        buffer.Add(b);
    else
        break;
}

readPtr = readPtr + buffer.Count + 1; // incrementing the …
Run Code Online (Sandbox Code Playgroud)

.net c# serialization pointers unmanaged

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

支持删除项目的线程安全集合

我似乎无法找到支持简单的Remove()函数的.NET线程安全/并发集合,我可以在其中删除特定项目或传入谓词以根据该项目删除项目.我试过了:

BlockingCollection<T>
ConcurrentQueue<T>
ConcurrentStack<T>
ConcurrentBag<T>
Run Code Online (Sandbox Code Playgroud)

有没有人知道支持这种行为的集合,还是我必须自己创建?

我希望能够从线程安全队列中获取下一个项目而不删除它,稍后如果满足某个条件,则继续删除它.

c# collections concurrency thread-safety concurrent-programming

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

条件事件等待/ ManualResetEvent

我知道如何使用ManualResetEvent或同步原语(如Monitor)来等待事件和/或锁,但我想知道是否有办法实现如下所示:

ManualResetEvent resetEvent; 

public string WaitForOneThousandMs()
{
    resetEvent.Wait(1000);

    if (WaitTime(resetEvent) <= 1000)
        return "Event occured within 1000ms."; 
    else
        return "Event did not occur within 1000ms."; 
}
Run Code Online (Sandbox Code Playgroud)

1)等待1000ms以发生事件X.

2)如果事件发生在1000ms内,则执行路径A.

3)否则,执行路径B.

这基本上是一个条件等待函数,其中条件是我们必须等待多长时间,如果可能的话,实现它的最佳方法是什么?

c# events multithreading synchronization manualresetevent

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