An entry point cannot be marked with the 'async' modifier
I copied below code from this link.But when I am compiling this code I am getting an entry point cannot be marked with the 'async' modifier. How can I make this code compilable?
class Program
{
static async void Main(string[] args)
{
Task<string> getWebPageTask = GetWebPageAsync("http://msdn.microsoft.com"); Debug.WriteLine("In startButton_Click before await");
string webText = await getWebPageTask;
Debug.WriteLine("Characters received: " + webText.Length.ToString());
} private static async Task<string> GetWebPageAsync(string url)
{
// Start an async task.
Task<string> getStringTask = (new HttpClient()).GetStringAsync(url); // Await the task. This is what happens:
// 1. Execution immediately returns to the calling method, returning a
// different task from the task created in the previous statement.
// Execution in this method is suspended.
// 2. When the task created in the previous statement completes, the
// result from the GetStringAsync method is produced by the Await
// statement, and execution continues within this method.
Debug.WriteLine("In GetWebPageAsync before await");
string webText = await getStringTask;
Debug.WriteLine("In GetWebPageAsync after await"); return webText;
} // Output:
// In GetWebPageAsync before await
// In startButton_Click before await
// In GetWebPageAsync after await
// Characters received: 44306
}
The error message is exactly right: the Main() method cannot be async, because when Main()returns, the application usually ends.
If you want to make a console application that uses async, a simple solution is to create an asyncversion of Main() and synchronously Wait() on that from the real Main():
static void Main()
{
MainAsync().Wait();
} static async Task MainAsync()
{
// your async code here
}
This is one of the rare cases where mixing await and Wait() is a good idea, you shouldn't usually do that.
from:http://stackoverflow.com/questions/16712172/an-entry-point-cannot-be-marked-with-the-async-modifier
from:http://www.itstrike.cn/Question/f33637bc-2f7f-47b3-9985-0fe709b24d57.html
| 
 I copied below code from this link.But when I am compiling this code I am getting an entry point cannot be marked with the 'async' modifier. How can I make this code compilable? 
 | 
An entry point cannot be marked with the 'async' modifier的更多相关文章
- Control Flow in Async Programs
		
Control Flow in Async Programs You can write and maintain asynchronous programs more easily by using ...
 - Dart 基础重点截取 Dart 2 20180417
		
官网教程 https://www.dartlang.org/guides/language/language-tour dart是一个单线程的语言,没有多线程 Final and const If y ...
 - CLR via C# 3rd - 08 - Methods
		
Kinds of methods Constructors Type constructors Overload operators Type con ...
 - 【转】 svn 错误 以及 中文翻译
		
直接Ctrl+F 搜索你要找的错 # # Simplified Chinese translation for subversion package # This file is distribute ...
 - 9.Methods(二)
		
4.Operator Overload Methods allow a type to define how operators should manipulate instances of the ...
 - [搬运] DotNetAnywhere:可供选择的 .NET 运行时
		
原文 : DotNetAnywhere: An Alternative .NET Runtime 作者 : Matt Warren 译者 : 张很水 我最近在收听一个名为DotNetRock 的优质播 ...
 - C# to IL 12 Arrays(数组)
		
An array is a contiguous block of memory that stores values of the same type. These valuesare an ind ...
 - DotNetAnywhere
		
DotNetAnywhere:可供选择的 .NET 运行时 原文 : DotNetAnywhere: An Alternative .NET Runtime作者 : Matt Warren译者 : ...
 - SVN错误信息汇总
		
svn错误信息 # # Simplified Chinese translation for subversion package # This file is distributed under ...
 
随机推荐
- Asp.Net Mvc 返回类型总结
			
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
 - day8.登陆注册简单实现
			
username = input('请输入注册的用户名:') password = input('请输入注册名的密码:') with open('list_of_info',mode='w',enco ...
 - Python 面向对象3-类变量与实例变量
			
#!/usr/bin/env python # -*- coding:utf-8 -*- # 作者:Presley # 邮箱:1209989516@qq.com # 时间:2018-08-05 # O ...
 - UOJ#62. 【UR #5】怎样跑得更快 数论 莫比乌斯反演
			
原文链接https://www.cnblogs.com/zhouzhendong/p/UOJ62.html 题解 太久没更博客了,该拯救我的博客了. $$\sum_{1\leq j \leq n} \ ...
 - HDU2732 Leapin' Lizards 网络流 最大流 SAP
			
原文链接http://www.cnblogs.com/zhouzhendong/p/8362002.html 题目传送门 - HDU2732 题意概括 给你一个网格,网格上的一些位置上有一只蜥蜴,所有 ...
 - redis虚拟内存
			
对于redis 这样的内存数据库, 内存总是不够用的. 除了可以将数据分割到多个 redis 服务器以外. 另外的能够提高数据库容量的办法就是使用虚拟内存技术把那些不经常访问的数据交换到磁盘上 如果我 ...
 - eclipse里面svn比较之前版本的代码
			
team——显示资源历史记录比较
 - CentOS7 Windows双系统 修复引导
			
伪前提:先装Windows再装CentOS7(伪前提是因为没试过先装CentOS再装Windows) Windows用U盘安装CentOS7后,开启启动项里面仅有CentOS7的启动项,要修复Wind ...
 - TF:利用TF的train.Saver载入曾经训练好的variables(W、b)以供预测新的数据—Jason niu
			
import tensorflow as tf import numpy as np W = tf.Variable(np.arange(6).reshape((2, 3)), dtype=tf.fl ...
 - HierarchicalClustering:编写HierarchicalClustering层次聚类算法—Jason niu
			
from numpy import * class cluster_node: def __init__(self,vec,left=None,right=None,distance=0.0,id=N ...