缺少异步操作文档? [英] Asynchronous operations documentation missing?

查看:62
本文介绍了缺少异步操作文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到关于同步和异步操作的任何文档?



我希望在Visual Studio 2010中找到一个能够缩放和读取的键盘快捷键有关被调用参数的更多信息,但我找不到多少,可以,请你帮忙吗?







I cannot find any documentation on synchronous and asynchronous operations?

I was hoping to find a keyboard shortcut in Visual Studio 2010 that enables me to zoom, and read more information on the parameters being called, but I could not quite find much, can, you help please?



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace SyncDelegateReview
{
    public delegate int BinaryOp (int x, int y);
    class Program
    {
        
        static void Main(string[] args)
        {
            Console.WriteLine("Main() invoked on thread {0}.", Thread.CurrentThread.ManagedThreadId);
            //invoke Add in a synchronous manner
            BinaryOp b = new BinaryOp(Add);
            
            //invoke Add() on a secondary thread
            b = new BinaryOp(Add);
            IAsyncResult iftAR = b.BeginInvoke(10, 10, null, null); 
//WHAT DO THE LAST TWO PARAMETERS MEAN PLEASE?
            Console.WriteLine("Other work on thread in Main(..)");

            //obtain result of the Add()
            int answer = b.EndInvoke(iftAR);
            Console.WriteLine("10 + 10 is {0} ", answer);
            Console.ReadLine();
        }

        static int Add(int x, int y)
        { 
            //write the ID of the executing thread
            Console.WriteLine("Add() invoked on thread {0}", Thread.CurrentThread.ManagedThreadId);
            //pause to simulate a lengthy operation
            Thread.Sleep(5000);
            return x + y;
        }
    }
}

推荐答案

您将找不到关于BeginInvoke调用的文档,因为它是由委托定义在运行中创建的方法。该方法实际上并不作为.NET Framework中的常规方法存在!



无论如何...... BeginInvoke列表中的第一个参数是您放置的参数在您的委托定义中, int x int y



下一个参数,第一个 null 代码的那一行,是一个在调用的方法返回时执行的回调函数。第二个 null 是一个传递来保存异步信息的对象,通常是一个状态对象。



最接近您将获得的文档是这个 [ ^ ]。就所讨论的参数而言,它几乎完全相同。
You won't find documentation on the BeginInvoke call because it's a method that's created "on-the-fly" by your delegate definition. The method doesn't actually exist as a normal method in the .NET Framework!

Anyway... the first parameters in the list for BeginInvoke are the parameters you put in your delegate definition, int x and int y.

The next parameter, the first null that line of your code, is a callback function that is executed when the invoked method returns. The second null is an object that is passed to hold async information, usually a state object.

The closest to documentation you're going to get is this[^]. It does pretty much the exact same thing as far as the parameters in question are concerned.


这篇关于缺少异步操作文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆