jjzjj

MoveNext

全部标签

c# - 如何取消 tailable 游标上的 MoveNext 操作

我正在使用MongoDB实现PubSub。如果我创建查询并指定带有NoCursorTimeout的TailableCursor:using(varenumerator=_Collection.FindAs(Query.GTE("CreationTimeUTC",DateTime.UtcNow)).SetFlags(QueryFlags.AwaitData|QueryFlags.NoCursorTimeout|QueryFlags.TailableCursor).SetSortOrder(SortBy.Ascending("$natural")).GetEnumerator)){whil

c# - MoveNext 而不是实际的方法/任务名称

使用log4net声明为:privatereadonlyILoglog=LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType());在异步方法或任务中,像这样:publicasyncvoidCheckSomething(){log.Info(null);//....}记录MoveNext而不是CheckSomething。知道如何让它记录实际的方法名称吗? 最佳答案 所有async方法都被重写到状态机中以满足方法中潜在的await值。代码所在的最后一个方法是

c# - MoveNext 而不是实际的方法/任务名称

使用log4net声明为:privatereadonlyILoglog=LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType());在异步方法或任务中,像这样:publicasyncvoidCheckSomething(){log.Info(null);//....}记录MoveNext而不是CheckSomething。知道如何让它记录实际的方法名称吗? 最佳答案 所有async方法都被重写到状态机中以满足方法中潜在的await值。代码所在的最后一个方法是

c# - 为什么 Enumerator.MoveNext 在与 using 和 async-await 一起使用时不能像我预期的那样工作?

我想通过一个List来枚举并调用异步方法。如果我这样做:publicasyncTaskNotWorking(){varlist=newList{1,2,3};using(varenumerator=list.GetEnumerator()){Trace.WriteLine(enumerator.MoveNext());Trace.WriteLine(enumerator.Current);awaitTask.Delay(100);}}结果是:True0但我希望它是:True1如果我删除using或awaitTask.Delay(100):publicvoidWorking1(){var

c# - Enumerator.MoveNext() 的奇怪行为

有人可以解释为什么这段代码在无限循环中运行吗?为什么MoveNext()总是返回true?varx=new{TempList=newList{1,3,6,9}.GetEnumerator()};while(x.TempList.MoveNext()){Console.WriteLine("HelloWorld");} 最佳答案 List.GetEnumerator()返回可变值类型(List.Enumerator)。您将该值存储在匿名类型中。现在,让我们看看它做了什么:while(x.TempList.MoveNext()){//I