首页 \ 问答 \ C#,从后台线程调用匿名方法(Action <>)(C#, invoke anonymous method (Action<>) from background thread)

C#,从后台线程调用匿名方法(Action <>)(C#, invoke anonymous method (Action<>) from background thread)

这应该很简单!

我想创建一个匿名的Action <>委托来执行GUI更新,我将从其他几个匿名委托调用它(它将在不同的线程上运行)。

    void Test() {

        Action<string> invokeDisplay = new Action<string>(delegate(string Element) {
            //Do a variety of things to my GUI depending on Element parameter
        });


        MethodInvoker opLong1 = new MethodInvoker(delegate() {

        //  Do long task

            this.Invoke(invokeDisplay("long1"));
        });

        MethodInvoker opLong2 = new MethodInvoker(delegate() {

        //  Do long task

            this.Invoke(invokeDisplay("long2"));
        });

        new Thread(new ThreadStart(opLong1)).Start();
        new Thread(new ThreadStart(opLong2)).Start();
    }

那么这条线的正确语法是什么?

            this.Invoke(invokeDisplay("long1"));

This should be simple!

I want to create an anonymous Action<> delegate to perform a GUI update, which I will call from several other anonymous delegates (which will be run on separate threads).

    void Test() {

        Action<string> invokeDisplay = new Action<string>(delegate(string Element) {
            //Do a variety of things to my GUI depending on Element parameter
        });


        MethodInvoker opLong1 = new MethodInvoker(delegate() {

        //  Do long task

            this.Invoke(invokeDisplay("long1"));
        });

        MethodInvoker opLong2 = new MethodInvoker(delegate() {

        //  Do long task

            this.Invoke(invokeDisplay("long2"));
        });

        new Thread(new ThreadStart(opLong1)).Start();
        new Thread(new ThreadStart(opLong2)).Start();
    }

So whats the correct syntax for this line?

            this.Invoke(invokeDisplay("long1"));

原文:https://stackoverflow.com/questions/18621565
更新时间:2023-07-11 17:07

最满意答案

过了一段时间,我在bouncyCastle应用程序的示例中找到了它的完成方式。

它实际上比我在IText中找到的更简单直接(没有取出框架本身的亲切性)。

代码类似于:

        AsymmetricCipherKeyPair signaturePair;
        X509Certificate signatureCert;

        IList certList = new ArrayList();
        IList crlList = new ArrayList();
        CmsProcessable msg = new CmsProcessableByteArray(Encoding.ASCII.GetBytes("I hate hello world!"));

        certList.Add(signatureCert);
        certList.Add(OrigCert);

        crlList.Add(SignCrl);

        IX509Store x509Certs = X509StoreFactory.Create(
            "Certificate/Collection",
            new X509CollectionStoreParameters(certList));
        IX509Store x509Crls = X509StoreFactory.Create(
            "CRL/Collection",
            new X509CollectionStoreParameters(crlList));

        CmsSignedDataGenerator gen = new CmsSignedDataGenerator();

        gen.AddSigner(signaturePair.Private, signatureCert, CmsSignedDataGenerator.DigestSha1);

        gen.AddCertificates(x509Certs);
        gen.AddCrls(x509Crls);

        CmsSignedData signedData = gen.Generate(msg, true);

        //saving in BER encoding
        Stream stream = new MemoryStream(signedData.GetEncoded());

After sometime, i've found how its done, in the examples inside the bouncyCastle app.

It's actually quite simpler and straight foward than i had found in IText (, not taking out the geniality of the framework itself).

The code is something like:

        AsymmetricCipherKeyPair signaturePair;
        X509Certificate signatureCert;

        IList certList = new ArrayList();
        IList crlList = new ArrayList();
        CmsProcessable msg = new CmsProcessableByteArray(Encoding.ASCII.GetBytes("I hate hello world!"));

        certList.Add(signatureCert);
        certList.Add(OrigCert);

        crlList.Add(SignCrl);

        IX509Store x509Certs = X509StoreFactory.Create(
            "Certificate/Collection",
            new X509CollectionStoreParameters(certList));
        IX509Store x509Crls = X509StoreFactory.Create(
            "CRL/Collection",
            new X509CollectionStoreParameters(crlList));

        CmsSignedDataGenerator gen = new CmsSignedDataGenerator();

        gen.AddSigner(signaturePair.Private, signatureCert, CmsSignedDataGenerator.DigestSha1);

        gen.AddCertificates(x509Certs);
        gen.AddCrls(x509Crls);

        CmsSignedData signedData = gen.Generate(msg, true);

        //saving in BER encoding
        Stream stream = new MemoryStream(signedData.GetEncoded());

相关问答

更多
  • 我做了一些鸭子去找到了rfc320,它提供了asn.1类的定义并让它起作用! 结构现在是: type SubjectPublicKeyInfo struct { Algorithm pkix.AlgorithmIdentifier SubjectPublicKey asn1.BitString } type PublicKeyAndChallenge struct { Spki SubjectPublicKeyInfo Challenge string } type Si ...
  • 错误在于: v3CertBuild.addExtension(Extension.authorityKeyIdentifier, false, x509ExtensionUtils.createAuthorityKeyIdentifier(pubKeyInfo).getKeyIdentifier()); v3CertBuild.addExtension(Extension.subjectKeyIdentifier, false, x509ExtensionUtils.createSubjectKeyIden ...
  • 问题是RSAFormatter.CreateSignature(paramDataToSign); 传递哈希值,而signer.update(paramDataToSign); 在散列之前传递数据。 因此,您可能必须删除Java代码的MessageDigest计算才能使其MessageDigest 。 或者,如果您只有哈希值,则可以查看Bouncy Castle轻量级API以查找接受预先哈希值的方法。 这可以使用new RSADigestSigner(new StaticDigest(paramDataTo ...
  • 解决 感谢所有我尝试了很多东西,但没有找到任何解决方案。最后我尝试下面,它的工作。 我做了以下更改并为我工作。 添加了新的jar文件版本是lib文件夹中的bcprov-ext-jdk15on-1.47.jar,并在MANIFEST.MF中为此jar文件创建条目 在MANIFEST.MF进行了更改后,我已经签署了bcprov-ext-jdk15on-1.47.jar和applet.jar文件,并为我工作。 谢谢。 Resolved Thanks to all I have tried many thing b ...
  • 经过同事/批配合的大量帮助,我终于能够解决这个问题了。 这就是我做的: 首先,我使用以下命令将pem证书转换为der证书 openssl pkcs8 -topk8 -inform PEM -outform DER -passin pass:passphrase -in "C:\Input\CERT.pem" -out "C:\Input\CERT.der"-nocrypt 然后我使用以下类根据上面收到的证书对给定字符串进行签名和编码: import java.io.*; import java.secur ...
  • 你看的文件是来自充气城堡的军团 充气城堡军团Java密码学API描述: Bouncy Castle Crypto包是加密算法的Java实现。 该软件包的组织方式使其包含一个适用于任何环境(包括新发布的J2ME)的轻量级API,并具有额外的基础结构,以使算法符合JCE框架。 该文件也可以从maven存储库下载。 您有错误,因为此类文件在Java类路径中不可用。 下载文件并将其放入WEB-INF/lib 。 The file are you looking is from The Legion of the B ...
  • 已经找到了一个解决方案,看起来像我一直看到的其他一些例子,但由于某些原因,这种方法效果更好:(以为我解决它的人命名的方法;) private static byte[] Rays(byte[] sigBytes) { bool highMsbR = (sigBytes[0] & 0x80) != 0; bool highMsbS = (sigBytes[20] & 0x80) != 0; ...
  • 我无法深入任何人都可以帮助我吗? 正如对象的名称所示,很可能不是,它是特定于应用程序的。 字符串输出中的21表示tag值,而不表示子元素的数量。 您可以调用getContents()来获取底层字节数组和getApplicationTag()来获取标记值(在您的情况下为21)。 如何解读这些数据,不知道没有更多细节。 I can not go deeper Can anyone help me? Most likely not, as name of object suggests, it is applic ...
  • 过了一段时间,我在bouncyCastle应用程序的示例中找到了它的完成方式。 它实际上比我在IText中找到的更简单直接(没有取出框架本身的亲切性)。 代码类似于: AsymmetricCipherKeyPair signaturePair; X509Certificate signatureCert; IList certList = new ArrayList(); IList crlList = new ArrayList(); ...
  • 要对jar进行签名,需要实现加密提供程序 如果您的提供商通过Cipher KeyAgreement , KeyGenerator , Mac或SecretKeyFactory类提供加密算法,则需要对JAR文件进行签名,以便JCA可以在运行时对代码进行身份验证。 Bouncycastle罐子签了名。 你已经将所有类重新打包到一个罐子里,但是你没有说你已经签了它,所以我猜你没有这样做。 SSHJ可能正在使用一些加密算法,无法初始化bouncycastle 选项: 使用代码签名证书对代码进行签名 与您的应用程序一 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。