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
最满意答案
过了一段时间,我在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; ...
-
阅读DER Application Specific(asn1-java-bouncycastle)(read a DER Application Specific (asn1-java-bouncycastle))[2023-09-09]
我无法深入任何人都可以帮助我吗? 正如对象的名称所示,很可能不是,它是特定于应用程序的。 字符串输出中的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 选项: 使用代码签名证书对代码进行签名 与您的应用程序一 ...