2

I'm working on MVC4 web application. This application allow users to interact with AD. The users can reset their passwords using same. However this whole task consume lot of time.

So at present, I had implemented swirl loading image to show user that the task is going on. Now my client wants to show progress bar in button itself as shown over here Buttons With Built-in Progress Meters or Progress Button Styles.

My idea was to get progress from server and update the progress style in button. I am able to discover how to report back to client the progress over Server by using SignalR with help of article at Reporting Server-Side Progress to Web Pages with SignalR.

The problem begins now. I am not able to discover how to measure that how much task of resetting password had been done and how much left.

So do you think these type of solutions truly feasible? If yes, please share with me any ideas or suggestions.

Vikram Singh Saini
  • 1,749
  • 3
  • 22
  • 42

2 Answers2

0

At some point you have to break this problem down into smaller pieces, and how far down you want to break down those pieces depends on how accurate you need this progress bar to be and how much time or money you're able to spend on the problem.

To you, how many steps are there to reset a password? In my eyes it's a simple call to SetPassword (there's a good question and answer out there already on this topic), which honestly should be pretty quick. The only reliable way to track that progress in my eyes is perhaps bumping counter to 50% right before firing off the SetPassword request and then completing to 100% once the call finishes.

If you have more steps than that, simply track a percentage as each method finishes. If that truly is your only call, I'm not sure how else to reliably track the percentage of a single call like SetPassword (if that call is taking more than a second or two you likely have some other problem that is causing such poor performance). Regardless, in the case where you do have a single call you will have to dig deeper to track progress (perhaps a file on disk indicates further progress, network bandwidth, memory usage, etc).

Community
  • 1
  • 1
Justin Helgerson
  • 24,900
  • 17
  • 97
  • 124
  • Thanks for answer! Your suggestions are impressive. I'll wait to see if anybody have more nice suggestions. But I really liked the suggestion of bumping counter. – Vikram Singh Saini Jun 30 '14 at 05:49
0

I have done something similar in a few of my projects at my last customer.

I created a little helper class that takes care of the actual threading stuff. It invokes a child container for our IoC (Ninject). In that child context I register a IUpdateProgess interface with a Thread scope lifetime. This way any classes that are invoked below will get the same IUpdateProgess but only for this certain thread (This will not work with async so keep that in mind, shouldnt be a problem for a background task). This way you can inject and update the progress for the current Background work from any class in the chain. (Use ASP.NET Background worker by the way so that IIS do not recycle the app domain before asking your worker if its ok).

The IUpdateProgess has one method

void Update(double progress); //Ranges from 0 - 1

When this method is fired the concrete implementation of IUpdateProgess will fire a message on the backend bus. I then use a little library of mine called SignalR.EventAggregatorProxy to forward these messages to all clients that listen to the specific worker type (In your case i guess only the one user should get it).

You can check out the library here https://github.com/AndersMalmgren/SignalR.EventAggregatorProxy/wiki

A blog post I wrote a bout it http://andersmalmgren.com/2014/05/27/client-server-event-aggregation-with-signalr/

This solution is abstracted and decoupled, anyone can subscribe to the progress, backend domain or front end clients alike.

Anders
  • 17,306
  • 10
  • 76
  • 144