I think they are advanced topics.

C#

  1. when will you use list, when will you use hashtable.

  2. when will you use Idispose.

  3.

Async and Await

public async Task<string> DoAsync5()
        {
           Task<string> mytask=Task.Run<string>(() =>
            {
                for (int j = 0; j < 20; j++)
                {
                    System.Threading.Thread.Sleep(100);
                    Console.Write("------------Async thread: " + j.ToString() + "\r\n");
                }

return "good";
            });

return await mytask;

//return "good";
            //Task.Factory.StartNew();

//IAsyncResult ar = mydoasync2.BeginInvoke(new AsyncCallback(CallbackMethod), mydoasync2);

//return result;

}

publicasyncTask<string> DoAsync()

{

Task<string> mytask = DoAsync5();

for (int i = 0; i < 100; i++)

{

System.Threading.Thread.Sleep(10);

Console.Write("Main thread: " + i.ToString() + "\r\n");

}

 

string mytaskResult = await mytask;

Console.Write("Both threads: " + mytaskResult);

return mytaskResult;

}

If you want to use await and async, you must call await twice.

1. In async function's definition.

2. In the excution funciton.

You must await a awaitable task!!!!!!

How to make a awaitable task. Define a task by task.run and await it......

It is strangely.

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("主线程测试开始..");
        AsyncMethod();
        Thread.Sleep(1000);
        Console.WriteLine("主线程测试结束..");
        Console.ReadLine();
    }
 
    static async void AsyncMethod()
    {
        Console.WriteLine("开始异步代码");
        var result = await MyMethod();
        Console.WriteLine("异步代码执行完毕");
    }
 
    static async Task<int> MyMethod()
    {
        for (int i = 0; i < 5; i++)
        {
            Console.WriteLine("异步执行" + i.ToString() + "..");
            await Task.Delay(1000); //模拟耗时操作
        }
        return 0;
    }

------------------------------------------------------------------------------------------

About begininvoker and callback.

you need to send the delegation itself to callback. If not, callback can't end this invoker correctly.

Now, there is theory and then there is practice. You have found, like
many other developers before you, that you can often get away with
ignoring this documented requirement. It may be an implementation detail
whether EndInvoke actually does anything that's absolutely
necessary to prevent your application from crashing, leaking memory,
etc. But here's the thing: if it's a documented requirement, you really ought to do it. This is not just about theory; it's about protecting yourself in the event of change.

By documenting this requirement, the designers of this asynchronous
calling mechanism basically gave themselves the freedom to change the
way BeginInvoke and EndInvoke work down the line so that, if there were sufficient reason (e.g., a performance enhancement), EndInvoke
could suddenly become a lot more necessary. Suppose it would suddenly
result in a deadlock if you forgot it. They've already covered
themselves by saying always call EndInvoke; if your app stops working because you didn't follow this requirement, the onus is on you.

I'm not saying this is necessarily a likely scenario. My point is simply that you shouldn't—or at least I wouldn't—ask "Is this really necessary?" with the mindset of If I can get away with leaving it out, then I will, since it is documented that you should do it.

http://stackoverflow.com/questions/4585042/is-delegate-endinvoke-really-necessary

Today's interview of C#的更多相关文章

  1. Pramp mock interview (4th practice): Matrix Spiral Print

    March 16, 2016 Problem statement:Given a 2D array (matrix) named M, print all items of M in a spiral ...

  2. WCF学习系列二---【WCF Interview Questions – Part 2 翻译系列】

    http://www.topwcftutorials.net/2012/09/wcf-faqs-part2.html WCF Interview Questions – Part 2 This WCF ...

  3. WCF学习系列一【WCF Interview Questions-Part 1 翻译系列】

    http://www.topwcftutorials.net/2012/08/wcf-faqs-part1.html WCF Interview Questions – Part 1 This WCF ...

  4. Amazon Interview | Set 27

    Amazon Interview | Set 27 Hi, I was recently interviewed for SDE1 position for Amazon and got select ...

  5. Java Swing interview

    http://www.careerride.com/Swing-AWT-Interview-Questions.aspx   Swing interview questions and answers ...

  6. Pramp - mock interview experience

    Pramp - mock interview experience   February 23, 2016 Read the article today from hackerRank blog on ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. [译]Node.js Interview Questions and Answers (2017 Edition)

    原文 Node.js Interview Questions for 2017 什么是error-first callback? 如何避免无止境的callback? 什么是Promises? 用什么工 ...

  9. WCF学习系列三--【WCF Interview Questions – Part 3 翻译系列】

    http://www.topwcftutorials.net/2012/10/wcf-faqs-part3.html WCF Interview Questions – Part 3 This WCF ...

  10. WCF学习系列四--【WCF Interview Questions – Part 4 翻译系列】

    WCF Interview Questions – Part 4   This WCF service tutorial is part-4 in series of WCF Interview Qu ...

随机推荐

  1. Silverlight分享一套企业开发主题

    Silverlight分享一套企业开发主题 Silverlight默认主题时间长了,也视觉疲劳了,于是上网上找了下Silverlight主题.发现SL的主题并不多,下面这套JetPack主题还是SL4 ...

  2. HDOJ(HDU) 2090 算菜价(简单水题、)

    Problem Description 妈妈每天都要出去买菜,但是回来后,兜里的钱也懒得数一数,到底花了多少钱真是一笔糊涂帐.现在好了,作为好儿子(女儿)的你可以给她用程序算一下了,呵呵. Input ...

  3. 《SDN核心技术剖析和实战指南》3.1控制器核心技术读书笔记

    在SDN的架构中,控制器可以说是SDN的核心,它负责对底层转发设备的控制以及向上层应用提供可编程性的北向接口.从实现上看,主要分三个层面来考虑,南向接口技术,北向接口技术以及东西向的可扩展性能力.下面 ...

  4. 使用 FreeMarker 替换 JSP 的 10 个理由

    你还在使用 Java 服务器页面(俗称JSP)吗?我曾经也是,但是几年前我抛弃了它们,并且再也没有用过JSP了.JSP 是个很好的概念,但是它却剥夺了 web 开发的乐趣. 对我而言,这些都是小事,比 ...

  5. JS中字符串倒序的两种方法

    var reverse = function( str ){ var stack = [];//生成一个栈 for(var len = str.length,i=len;i>=0;i-- ){ ...

  6. Transact-SQL 数据类型转换

    Syntax   Syntax for CAST: CAST ( expression AS data_type [ ( length ) ] )     Syntax for CONVERT: CO ...

  7. jvm之内存分配与回收策略

    1.java堆中各代分布 (1)Young:主要是用来存放新生的对象. (2)Old:主要存放应用程序中生命周期长的内存对象. (3)Permanent:是指内存的永久保存区域,主要存放Class和M ...

  8. 通过yum升级CentOS/RHEL最小化安装

    1.如果你有安装CentOS / RHEL最小服务器安装,您可能有很多麻烦没有安装包 2.有一种方法来安装所有的包,需要一个基本的服务器,使用yum groupinstall命令 3.从最小的安装基本 ...

  9. 外网访问自己的tomcat

    我们平常学习时经常会写一下javaweb程序,我们为了更能逼近现实,就想着自己的javaweb程序发布后,外网的同学能够访问我们的网站,难道我们去买空间,去买域名嘛,其实也没必要,我们只是学习,测试之 ...

  10. 如何使用css、布局横向导航栏

    使用css布局横向导航栏,css应用给网页样式的方式,就相当于,给人怎么去穿上衣服,不同的衣服有不同的穿法,这里我们使用的是内联式.在这里 我们可以适当的把值调的大一点,这样我们就可以很容易的对比. ...