惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Project Zero
Project Zero
月光博客
月光博客
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
O
OpenAI News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Know Your Adversary
Know Your Adversary
Last Week in AI
Last Week in AI
S
Securelist
Engineering at Meta
Engineering at Meta
博客园 - 司徒正美
P
Privacy & Cybersecurity Law Blog
T
Tailwind CSS Blog
F
Fortinet All Blogs
博客园 - 三生石上(FineUI控件)
Scott Helme
Scott Helme
MyScale Blog
MyScale Blog
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
C
Cisco Blogs
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
小众软件
小众软件
U
Unit 42
Microsoft Azure Blog
Microsoft Azure Blog
Hacker News: Ask HN
Hacker News: Ask HN
Hugging Face - Blog
Hugging Face - Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
SecWiki News
SecWiki News
宝玉的分享
宝玉的分享
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hackread – Cybersecurity News, Data Breaches, AI and More
L
Lohrmann on Cybersecurity
IT之家
IT之家
Security Archives - TechRepublic
Security Archives - TechRepublic
I
InfoQ
S
Security @ Cisco Blogs
Webroot Blog
Webroot Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
F
Full Disclosure
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The GitHub Blog
The GitHub Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Jina AI
Jina AI
Cyberwarzone
Cyberwarzone
人人都是产品经理
人人都是产品经理
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
B
Blog RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research

博客园 - roboth

转:“由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值”的解决方法 .net tostring format格式说明 - roboth 一、DIP简介(DIP--Dependency Inversion Principle): 请确认 &lt;Import&gt; 声明中的路径正确,且磁盘上存在该文件。 Visual Studio 最常用的13个快捷键 H1N1:速饮配方 通过注册表获取文件的ContentType [转]解决ASP.NET Web Applicatio超时时间已到.在操作完成之前超时时间已过或服务器未响应 - roboth 在线创建pdf msdn之sp_xml_preparedocument Route命令使用详解 电子书下载 买药记 抓取图片 xslt之<xsl:apply-templates - roboth - 博客园 盲人摸象 sql产生日历表 dom操作时机 js小技巧之访问元素属性
异步委托
roboth · 2009-07-24 · via 博客园 - roboth

using System;
using System.Threading;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Messaging;// Create an asynchronous delegate.
public delegate bool FactorizingAsyncDelegate(
         
int factorizableNum,
         
ref int primefactor1,
         
ref int primefactor2);// Create a class that factorizers the number.
public class PrimeFactorizer
{
    
public bool Factorize(
                 
int factorizableNum,
                 
ref int primefactor1,
                 
ref int primefactor2)
    {
        primefactor1 
= 1;
        primefactor2 
= factorizableNum;// Factorize using a low-tech approach.
        for (int i = 2; i < factorizableNum; i++)
        {
            
if (0 == (factorizableNum % i))
            {
                primefactor1 
= i;
                primefactor2 
= factorizableNum / i;
                
break;
            }
        }
if (1 == primefactor1)
            
return false;
        
else
            
return true;
    }
}
// Class that receives a callback when the results are available.
public class ProcessFactorizedNumber
{
    
private int _ulNumber;public ProcessFactorizedNumber(int number)
    {
        _ulNumber 
= number;
    }
// Note that the qualifier is one-way.
    [OneWayAttribute()]
    
public void FactorizedResults(IAsyncResult ar)
    {
        
int factor1 = 0, factor2 = 0;// Extract the delegate from the AsyncResult.  
        FactorizingAsyncDelegate fd = (FactorizingAsyncDelegate)((AsyncResult)ar).AsyncDelegate;// Obtain the result.
        fd.EndInvoke(ref factor1, ref factor2, ar);// Output the results.
        Console.WriteLine("On CallBack: Factors of {0} : {1} {2}",
                      _ulNumber, factor1, factor2);
    }
}
// Class that shows variations of using Asynchronous
public class Simple
{
    
// The following demonstrates the Asynchronous Pattern using a callback.
    public void FactorizeNumber1()
    {
        
// The following is the client code.
        PrimeFactorizer pf = new PrimeFactorizer();
        FactorizingAsyncDelegate fd 
= new FactorizingAsyncDelegate(pf.Factorize);int factorizableNum = 1000589023, temp = 0;// Create an instance of the class that is going 
        
// to be called when the call completes.
        ProcessFactorizedNumber fc = new ProcessFactorizedNumber(factorizableNum);// Define the AsyncCallback delegate.
        AsyncCallback cb = new AsyncCallback(fc.FactorizedResults);// You can use any object as the state object.
        Object state = new Object();// Asynchronously invoke the Factorize method on pf.
        IAsyncResult ar = fd.BeginInvoke(
                             factorizableNum,
                             
ref temp,
                             
ref temp,
                             cb,
                             state);
//
        
// Do some other useful work.
        
//. . .
    }// The following demonstrates the Asynchronous Pattern using a BeginInvoke, followed by waiting with a time-out.
    public void FactorizeNumber2()
    {
        
// The following is the client code.
        PrimeFactorizer pf = new PrimeFactorizer();
        FactorizingAsyncDelegate fd 
= new FactorizingAsyncDelegate(pf.Factorize);int factorizableNum = 1000589023, temp = 0;// Create an instance of the class that is going 
        
// to be called when the call completes.
        ProcessFactorizedNumber fc = new ProcessFactorizedNumber(factorizableNum);// Define the AsyncCallback delegate.
        AsyncCallback cb =
        
new AsyncCallback(fc.FactorizedResults);// You can use any object as the state object.
        Object state = new Object();// Asynchronously invoke the Factorize method on pf.
        IAsyncResult ar = fd.BeginInvoke(
                          factorizableNum,
                          
ref temp,
                          
ref temp,
                          
null,
                          
null);

        ar.AsyncWaitHandle.WaitOne(

10000false);if (ar.IsCompleted)
        {
            
int factor1 = 0, factor2 = 0;// Obtain the result.
            fd.EndInvoke(ref factor1, ref factor2, ar);// Output the results.

            Console.WriteLine(
"Sequential : Factors of {0} : {1} {2}",
                          factorizableNum, factor1, factor2);

        }
    }

public static void Main(String[] args)
    {
        Simple simple 
= new Simple();
        simple.FactorizeNumber1();
        simple.FactorizeNumber2();
    }
}