HttpClient提供的不是真正的异步操作吗?(HttpClient provide not truly async operations?)
我对异步IO操作感到困惑。 在本文中, Stephen Cleary解释说我们不应该使用
Task.Run(() => SomeIoMethod())
因为真正的异步操作应该使用.NET中的标准P / Invoke异步I / O系统
http://blog.stephencleary.com/2013/11/there-is-no-thread.html
但是,避免库中的“伪异步”。 假异步是指组件具有异步就绪API,但它是通过将同步API包装在线程池线程中来实现的。 这对ASP.NET的可伸缩性起反作用。 假异步的一个突出例子是Newtonsoft JSON.NET,这是一个非常出色的库。 最好不要调用(假的)异步版本来序列化JSON; 只需调用同步版本。 虚假异步的一个棘手的例子是BCL文件流。 打开文件流时,必须显式打开它以进行异步访问; 否则,它将使用伪异步,同步阻塞文件读写线程池线程。
他建议使用HttpClient但内部使用
Task.Factory.StartNew()
这是否意味着
HttpClient
不提供真正的异步操作?I'm confused about async IO operations. In this article Stephen Cleary explains that we should not use
Task.Run(() => SomeIoMethod())
because truly async operations should usestandard P/Invoke asynchronous I/O system in .NET
http://blog.stephencleary.com/2013/11/there-is-no-thread.html
However, avoid “fake asynchrony” in libraries. Fake asynchrony is when a component has an async-ready API, but it’s implemented by just wrapping the synchronous API within a thread pool thread. That is counterproductive to scalability on ASP.NET. One prominent example of fake asynchrony is Newtonsoft JSON.NET, an otherwise excellent library. It’s best to not call the (fake) asynchronous versions for serializing JSON; just call the synchronous versions instead. A trickier example of fake asynchrony is the BCL file streams. When a file stream is opened, it must be explicitly opened for asynchronous access; otherwise, it will use fake asynchrony, synchronously blocking a thread pool thread on the file reads and writes.
And he advises to use HttpClient but internaly it use
Task.Factory.StartNew()
Does this mean that
HttpClient
provides not truly async operations?
原文:https://stackoverflow.com/questions/39931213
最满意答案
在MonthView Change Weeks中显示为3也会在委托方法setBeginingofmonth中注释以下代码
for(JTCalendarWeekView *view in weeksViews) { view.currentMonthIndex = currentMonthIndex; [view setBeginningOfWeek:currentDate]; NSDateComponents *dayComponent = [NSDateComponents new]; dayComponent.day = 7; currentDate = [calendar dateByAddingComponents:dayComponent toDate:currentDate options:0]; // Doesn't need to do other weeks // if(self.calendarManager.calendarAppearance.isWeekMode) // { // break; // } }
在JTCalendar updatePage方法中,如下所示更改7到14
if(!self.calendarAppearance.isWeekMode) { dayComponent.month = currentPage - (NUMBER_PAGES_LOADED / 2); } else { //to show next starting week for two weeks mode put 14 dayComponent.day = 14 * (currentPage - (NUMBER_PAGES_LOADED / 2)); }
In MonthView Change Weeks to display as 3 also do this comment the following code in delegate method setBeginingofmonth
for(JTCalendarWeekView *view in weeksViews) { view.currentMonthIndex = currentMonthIndex; [view setBeginningOfWeek:currentDate]; NSDateComponents *dayComponent = [NSDateComponents new]; dayComponent.day = 7; currentDate = [calendar dateByAddingComponents:dayComponent toDate:currentDate options:0]; // Doesn't need to do other weeks // if(self.calendarManager.calendarAppearance.isWeekMode) // { // break; // } }
in JTCalendar updatePage method change 7 to 14 as below
if(!self.calendarAppearance.isWeekMode) { dayComponent.month = currentPage - (NUMBER_PAGES_LOADED / 2); } else { //to show next starting week for two weeks mode put 14 dayComponent.day = 14 * (currentPage - (NUMBER_PAGES_LOADED / 2)); }
相关问答
更多-
如何在两周模式下实现日历视图(使用JTCalendar示例)(how to implement Calendar view in two weeks mode(Used JTCalendar example))[2023-05-29]
在MonthView Change Weeks中显示为3也会在委托方法setBeginingofmonth中注释以下代码 for(JTCalendarWeekView *view in weeksViews) { view.currentMonthIndex = currentMonthIndex; [view setBeginningOfWeek:currentDate]; NSDateComponents *dayComponent = [NSDateComponents n ... -
for (NSManagedObject *obj in matchingData) { alarmDate = [obj valueForKey:@"alarmDate"]; return alarmDate;' 无论您在方法参数中的日期是什么,总是返回第一个对象的alamrDate。 使用您的参数检查日期,然后返回此日期是否有alerm。 for (NSManagedObject *obj in matchingData) { ...
-
不知道这是否会为你工作...可能需要一些主要的调整,但这应该让你在正确的道路上..如果不让我知道。 function getWeek(fromDate) { var sunday = new Date(fromDate.setDate(fromDate.getDate() - fromDate.getDay())), result = [new Date(sunday)]; while (sunday.setDate(sunday.getDate() + 1) && sunday.ge ...
-
如果上面的代码编译时没有抱怨(换句话说,如果您将JTCalendar构建为项目中的库或框架),则可以将自定义视图对象拖动到要添加JTCalendar的任何视图中(即最有可能是视图)在故事板或XIB文件中的视图控制器内)。 将自定义视图拖动到位后,将自定义视图的自定义类设置为JTCalendarMenuView和/或JTHorizontalCalendarView。 此时,您将能够将视图控制器中的IBOutlet拖动连接到自定义视图对象。 If the code above is compiling with ...
-
星期一的日历开始周(Calendar start weeks at Monday)[2023-05-31]
在你的day_of_week数组中,更改天数的顺序,以便星期日到最后。 而不是这个: var day_of_week = new Array('So', 'Mo', 'Di','Mi', 'Do', 'Fr', 'Sa') 做这个: var day_of_week = new Array('Mo', 'Di','Mi', 'Do', 'Fr', 'Sa', 'So') 此外,您应该快速阅读帮助以了解如何创建指向Codepen等外部网站的链接(如果需要,请在问题编辑器中使用问号'?')。 这将有助于你发布代码 ... -
要解决此问题,您应该使用UICollectionView并创建自己的UICollectionViewLayout 。 有关自定义UICollectionViewLayouts精彩文章可以在这里找到。 在本文中,它专门讨论了一个有限的日历布局,它提供了一周。 To tackle this issue you should use a UICollectionView and create your own UICollectionViewLayout. A brilliant article on custo ...
-
如何使用Google Calendar API在未来两周内制定时间表?(How to get schedule in next two weeks by using Google Calendar api?)[2022-04-08]
有很多方法可以解决这个问题。 所有代码示例都可以从提供的链接中找到。 这是解决问题的方法: 要在时间范围内(即2周等)检索日历事件,请使用Events.list资源。 这允许您根据事件的开始/结束时间过滤事件。 请参阅以下参数: timeMax - 设置事件开始时间的上限以进行过滤。 timeMin - 设置事件结束时间的下限以进行过滤。 更新/修改事件详细信息,例如描述,摘要等.Events.patch将允许通过calendarID和eventID更新事件资源 。 你开始朝着正确的方向前进 就在那里。 尝 ... -
在JTCalendar的代表中: - (void)calendar:(JTCalendarManager *)calendar prepareDayView:(JTCalendarDayView *)dayView { if([self haveTaskForDay:dayView.date]) { dayView.dotView.hidden = NO; dayView.dotView.bac ...
-
也许你可以试试calendar-ui: http : //github.com/muhku/calendar-ui Maybe you can give calendar-ui a try: http://github.com/muhku/calendar-ui
-
我能够解决这个问题。 问题是教程设置了选定视图的大小并将其保留在那里。 我做的是 在CellView.swift制作出口宽度和高度约束 在ViewContoller.swift ,我修改了单元格选择,如下所示: if cellState.isSelected { var parentMinDimension = min(view.frame.width, view.frame.height) parentMinDimension = round(parentMinDimension - 0. ...