How to use SignalR to notify web clients from ASP.NET MVC 3 that MSMQ tasks were completed
By : user3782142
Date : March 29 2020, 07:55 AM
it helps some times If I understand correctly, you need a way of associating a task to a given user/client so that you can tell the client when their task has completed. SignalR API documentation tells me you can call JS methods for specific clients based on the client id ( https://github.com/SignalR/SignalR/wiki/SignalR-Client). In theory you could do something like: code :
string clientId = processedMessage.ClientId //Stored when you originally queued it.
IConnection connection = Connection.GetConnection<ProcessNotificationsConnection>();
connection.Send(clientId, "Your data was processed");
public class MyHub : Hub
{
public void Send(string data)
{
// Invoke a method on the calling client
Caller.addMessage(data);
// Similar to above, the more verbose way
Clients[Context.ClientId].addMessage(data);
// Invoke addMessage on all clients in group foo
Clients["foo"].addMessage(data);
}
}
|
Blocking tasks until previous task has completed
By : john
Date : March 29 2020, 07:55 AM
may help you . Use Task parallel library.. Task.Factory.StartNew(METHOD).ContinueWith(task => DispatcherHelper.Dispatch(() => { Mouse.OverrideCursor = null; }));
|
Multiple executor tasks notify master on completed?
By : Evan Johnson
Date : March 29 2020, 07:55 AM
I hope this helps . This sounds like a job of ExecutorService.invokeAll. code :
Collection<Callable> tasks = <get all sub tasks>;
executorService.invokeAll(tasks);
// Execution proceeds at the following line only once all "tasks" have been run
for (Runnable task:tasks) {
futures.add(executorService.submit(task));
}
for (Future<Void> result:futures) {
result.get();
}
|
Consuming blocking collection with multiple tasks/consumers
By : Siew Jin Kung Lim
Date : March 29 2020, 07:55 AM
This might help you A few small things You never called CompleteAdding, by not doing that your consuming foreach loops will never complete and hang forever. Fix that by doing users.CompleteAdding() after the initial for loop. You never wait for the work to finish, Run() will spin up your 100 threads (which likely WAY too much unless your real process involves a lot of waiting for uncontested resources). Because Tasks are not foreground threads they will not keep your program open when your Main exits. You need a CountdownEvent to track when everything is done. You don't start up your consumers till after your producer has finished all of it's work, you should spin off the producer in to a separate thread or start the consumers first so they are ready to work while you populate the producer on the main thread. code :
class Program
{
private const int MaxThreads = 100; //way to high for this example.
private static readonly CountdownEvent cde = new CountdownEvent(MaxThreads);
public static readonly BlockingCollection<User> users = new BlockingCollection<User>();
static void Main(string[] args)
{
Run();
for (int i = 0; i < 100000; i++)
{
var u = new User {Id = i, Name = "user " + i};
users.Add(u);
}
users.CompleteAdding();
cde.Wait();
}
static void Run()
{
for (int i = 0; i < MaxThreads; i++)
{
Task.Factory.StartNew(Process, TaskCreationOptions.LongRunning);
}
}
static void Process()
{
foreach (var user in users.GetConsumingEnumerable())
{
Console.WriteLine(user.Id);
}
cde.Signal();
}
}
public class User
{
public int Id { get; set; }
public string Name { get; set; }
}
|
NSURLSession notify when all tasks are completed
By : user3301023
Date : March 29 2020, 07:55 AM
it helps some times I think you need to track this yourself. Consider keeping an array of task objects. As you start a task, add the task object to the array. When the task is finished, remove the task object from the array. When you arrive at zero tasks in the array, you are done.
|