Comments (10)
The Sync.ExcecuteTaskAsync(...)
call seems to imply that TweetInvi has its own sync-to-async wrapper which is possibly making assumptions that don't quite hold in all cases. I only say this because in the TweetInvi wiki none of the examples I've come across so far seems to do anything async and there's no Sync.ExcecuteTaskAsync(...)
to be found.
from asyncex.
Here's the awesome
code ;)
https://github.com/linvi/tweetinvi/blob/master/Tweetinvi/Sync.cs#L43
I suspect the problem lies in there. Perhaps take that code, or a variant of it, into your own code and then you can step through it more easily. I'd add some logging in there too.
It really sounds like it's doing a sync-over-async style API (search the pfxteam blog for articles about that) which can be tricky.
from asyncex.
Thanks for bringing up those details, @IanYates.
The problem is that the default ITaskFactory.ExecuteTaskAsync
implementation is using Task.Factory.StartNew
without specifying a TaskScheduler
. The default value for TaskScheduler
is (unfortunately) TaskScheduler.Current
, not TaskSchedler.Default
.
Since AsyncContext
uses TaskScheduler
, this means the ITaskFactory
is in fact trying to queue its work on the AsyncContext
, not the ThreadPool
.
from asyncex.
Thanks, for looking into this so quickly I will read your article and update the library if needed!
from asyncex.
Thanks for taking a look at this, both of you. For now, I have my project working by just waiting on Task.Result (since my project depends on TweetInvi, I can't just remove that), but I would like to be able to use AsyncContext with it. It sounds like the issue is with TweetInvi, then? Is that right?
from asyncex.
Quick question to you. I am well used to threads but I do have less knowledge on the async/await.
Quickly reading your article, would you agree that instead of await Task.Factory.StartNew(action);
, I should use await TaskEx.Run(action);
, or is defining the TaskCreateOption
manually a better option?
from asyncex.
I would say to just call TaskEx.Run
. There are several less-than-satisfactory defaults with StartNew
. Since you're using Microsoft.Bcl.Async, a proper call would look something like Task.Factory.StartNew(action, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default)
, which is very long compared to TaskEx.Run(() => action())
. :)
from asyncex.
The new version of AsyncContext
hides the current TaskScheduler
.
While I think this is technically incorrect, this kind of bug is found all over the place (almost all uses of StartNew
/ContinueWith
on the Internet are wrong). As such, the new AsyncContext
goes out of its way to hide its TaskScheduler
.
from asyncex.
With the new AsyncContext, will Tweetinvi need to upgrade/change some of the code?
from asyncex.
No, Tweetinvi doesn't have to change. The hiding of the TaskScheduler
works around that bug.
However, I still do recommend using Task.Run
(or at least specifying TaskScheduler.Default
). It works with the new AsyncContext
, but it may not work with other custom contexts.
from asyncex.
Related Issues (20)
- Support AsyncProducerConsumerQueue wait for empty
- AsyncCollection IsEmpty HOT 3
- [Discussion] Return `ValueTask` instead of `AwaitableDisposable`? HOT 5
- [Question] .WaitAndUnwrapException() vs AsyncContext and potential deadlock HOT 2
- The collection has been marked as complete with regards to additions HOT 1
- Atomic wait semantics lead to continued processing after cancellation HOT 3
- What happened to NotifyTask? HOT 1
- CancellationTokenTaskSource's dispose
- Using LazyAsync with JSONSeralizer? HOT 1
- Producer/Consumer PriorityQueue
- doc/TaskConstants.md links to an article that doesn't exist anymore
- Cross thread Sync context stealing HOT 2
- [Question] Using discard with AsyncLock HOT 1
- [Question] Is ConfigureAwait(false) is needed? HOT 1
- AsyncContext holds exceptions until all tasks complete.
- Feature request: AsyncReaderWriterLock support for UpgradeableReadLock HOT 11
- The ApmAsyncFactory interop hangs if a path in async method returns synchronously. HOT 1
- Setting AsyncAutoResetEvent after used in Task.WhenAny HOT 3
- AsyncLazy with API call is being called twice across 4 components. HOT 2
- Strong names HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from asyncex.