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 async
version 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 ...
随机推荐
- outlook邮件中样式问题
目前要做一个定时发送邮件的功能,邮件的大致内容布局如下: HTML中 在QQ邮件中,可以进行正常显示. 在outlook网页版,也可以正常显示, outlook客户端 但是到了客户端就会出现很多很神奇 ...
- 前端接口自动化测试工具-DOClever使用介绍(转载)
DOClever 不仅集成了文档编写,团队协作,接口运行,mock 数据等功能,还有两个功能是让我们团队大大的提高工作效率的.一个是接口的自动化生成,可以根据接口数据自动生成文档信息,还有一个便是本文 ...
- hive中使用union出现异常数据
select * from tbl where id=2 union select * from tbl where id =1 如果hive使用union这么查询的时候,我们会发现数据变乱了. 解决 ...
- 利用Flume将MySQL表数据准实时抽取到HDFS
转自:http://blog.csdn.net/wzy0623/article/details/73650053 一.为什么要用到Flume 在以前搭建HAWQ数据仓库实验环境时,我使用Sqoop抽取 ...
- 2017Nowcoder Girl D - 打车
题目描述 妞妞参加完Google Girl Hackathon之后,打车回到了牛家庄. 妞妞需要支付给出租车司机车费s元.妞妞身上一共有n个硬币,第i个硬币价值为p[i]元. 妞妞想选择尽量多的硬币, ...
- linux定时任务相关
定时任务所在文件夹 /etc/crontab 定时任务重启命令 service crond restart
- TF之NN:matplotlib动态演示深度学习之tensorflow将神经网络系统自动学习并优化修正并且将输出结果可视化—Jason niu
import tensorflow as tf import numpy as np import matplotlib.pyplot as plt def add_layer(inputs, in_ ...
- poj 2502 Subway【Dijkstra】
<题目链接> 题目大意: 某学生从家到学校之间有N(<200)条地铁,这个学生可以在任意站点上下车,无论何时都能赶上地铁,可以从一条地铁的任意一站到另一条地跌的任意一站,学生步行速度 ...
- f5到底刷新了点什么,你知道吗
引言 前面翻到了http缓存相关内容,关于强制缓存和协商缓存,他们之间的差别可能大家比较清楚. 并且常规情况下是否该使用缓存以及使用哪种缓存, 相关文章多且全,这里不再赘述. 不过用户的不同行为会打破 ...
- Django 学习第四天——Django 模板标签
一.模板标签: 作用:标签在渲染的过程中提供任意的逻辑:例如 if for...in... 等 标签语法:由 {% %} 来定义的:例如:{% tag %}xxx{% endtag %} 常用标签: ...