task-parallel-library

Microsoft.AspNetCore.Identity UserManager GetUserAsync

南笙酒味 提交于 2019-12-24 07:19:39
问题 I've been reading the source code of UserManager.cs and I've stepped into the following block: public virtual Task<TUser> GetUserAsync(ClaimsPrincipal principal) { if (principal == null) { throw new ArgumentNullException(nameof(principal)); } var id = GetUserId(principal); return id == null ? Task.FromResult<TUser>(null) : FindByIdAsync(id); } I've been very curious if there is a reason why the above is not like this: public virtual async Task<TUser> GetUserAsync(ClaimsPrincipal principal) {

Reactive Extensions and parallel processing

折月煮酒 提交于 2019-12-24 07:13:04
问题 I am planning on using Rx within a project of mine at some point, and I have been researching into what I can do with Rx. My project uses TPL for processing state machine transitions in parallel (utilising all available processor cores). However, to improve performance, I want to replace the current IList<> pull mechanism with an Rx push mechanism. As I do not know very much about this technology I want to ascertain whether Rx will be compatible with pushing tokens to the parallel state

Tasks and Thread Scheduling in Asp.Net

拟墨画扇 提交于 2019-12-24 07:05:51
问题 In a Asp.Net Web page button click I have below code //Code is running on Asp.Net worker Thread var httpClient = new HttpClient(); var task = httpClient.GetAsync("/someapiCall"); //Creates a new thread and executed on it task.Wait(); Now when I call task.Wait what will happen to the worker thread? Will it be in suspended state waiting for the httpClient call to complete? Will it be returned to thread pool and be available to process other requests? Is there any difference between the above

Not reach the code as expected

蹲街弑〆低调 提交于 2019-12-24 06:55:52
问题 I have a telephony application, in which I want to invoke simultaneous calls,. Each call will occupy a channel or port. So I added all channels to a BlockingCollection. The application is a windows service. Let's see the code. public static BlockingCollection<Tuple<ChannelResource, string>> bc = new BlockingCollection<Tuple<ChannelResource, string>>(); public static List<string> list = new List<string>();// then add 100 test items to it. The main application has the code: while (true) {

Not reach the code as expected

与世无争的帅哥 提交于 2019-12-24 06:53:07
问题 I have a telephony application, in which I want to invoke simultaneous calls,. Each call will occupy a channel or port. So I added all channels to a BlockingCollection. The application is a windows service. Let's see the code. public static BlockingCollection<Tuple<ChannelResource, string>> bc = new BlockingCollection<Tuple<ChannelResource, string>>(); public static List<string> list = new List<string>();// then add 100 test items to it. The main application has the code: while (true) {

Should/Could this “recursive Task” be expressed as a TaskContinuation?

断了今生、忘了曾经 提交于 2019-12-24 05:54:07
问题 In my application I have the need to continually process some piece(s) of Work on some set interval(s). I had originally written a Task to continually check a given Task.Delay to see if it was completed, if so the Work would be processed that corresponded to that Task.Delay . The draw back to this method is the Task that checks these Task.Delays would be in a psuedo-infinite loop when no Task.Delay is completed. To solve this problem I found that I could create a "recursive Task " (I am not

Wait() causes UI thread to hang - when should Wait() be used?

我们两清 提交于 2019-12-24 05:39:14
问题 I have the following code that connects to a SignalR Hub private static async Task StartListening() { try { var hubConnection = new HubConnection("http://localhost:8080/"); IHubProxy hubProxy = hubConnection.CreateHubProxy("Broadcaster"); hubProxy.On<EventData>("notifyCardAccessEvent", eventData => { Log.Info(string.Format("Incoming data: {0} {1}", eventData.Id, eventData.DateTime)); }); ServicePointManager.DefaultConnectionLimit = 10; await hubConnection.Start(); Log.Info("Connected"); }

C# Improve parallel performance of Sparse Matrix Row and Column Total Calculations

大兔子大兔子 提交于 2019-12-24 04:35:13
问题 I have a sparse matrix containing roughly 100 million non-zero elements: // [Row][Column][Element] public IDictionary<int, IDictionary<int, decimal>> MyMatrix { get; private set; } Getting the sum of each row is very fast: private void RowSum() { var rowTotals = new ConcurrentDictionary<int, decimal>(); Parallel.ForEach(MyMatrix, (row) => { rowTotals.TryAdd(row.Key, row.Value.Sum(x => x.Value)); }); } Getting the sum of each column is much slower: private void ColumnSum() { var columnTotals =

How to return awaitable (Task?) that waits for an event in Dispatcher Thread

久未见 提交于 2019-12-24 04:09:04
问题 I have threads: UI thread with Dispatcher loop background thread that listens for messages in a queuing framework. when a message is received, an event is fired in the background thread: messageReceiver.Received += (sender, args) => ... In UI thread I would like to await a message, something like this: void ButtonClicked(object sender, RoutedEventArgs e) { await NextMessage(); //should return when messageReceiver.Received is fired } How to implement awaitable NextMessage method, so it does

Queuing BankgroundJob with Hangfire within an async action in ASP.NET MVC freeze the application

ⅰ亾dé卋堺 提交于 2019-12-24 03:30:47
问题 I have this action on one of my controllers which is called by another method which has been called also by another action. All works fine, unless I try to en-queue with Hangfire some jobs: _bankClient.FetchAndEnsureTransactionsAsync and _bankClient.RefreshItemAsync . This is causing the application to freeze (the client, browser, stops while the server is still running). I suppose is some weird deadlock , but nothing I've tried seems to make it work! Would someone know how to solve this