English 中文(简体)
Control concurrency in multiple users web application gridview
原标题:

Guys i m with a big problem.

I m running a backoffice application, and imagine, i have a form than contains a gridview editable.

  1. 100 Users go to the page
  2. 100 Users view the form page as the data provided from database
  3. 100 Users edit some fields
  4. How control the final data and consistency in this example?
问题回答

Before you can plan and implement the technical solution to this, ie. the code, you need to design the overall solution.

In other words, consider that you handed out 100 pieces of paper to 100 different people, each with a copy of that web-form on it. Those 100 people scribble notes on their paper, and then hand it back to you, in a random order.

How do you handle consistency in this scenario? When you can answer that, you can implement it.

Without knowing more about the data you have in that form, it will be practically impossible to give you concrete advice however.

Depends on what you want really. Do you have requirements? Are you fishing for suggestions?

One possible solution

If you have an explicit save action that is invoked when editing is complete,

  1. User navigates to page,
  2. User modifies table,
  3. User "saves",
  4. Page retrieves current values from datastore (as of time of save)
  5. Page compares current values to modified values
  6. Any conflicts are highlighted and requests user "resolve" the conflict
  7. Goto step 3. until there are no conflicts detected

Another possible solution

If you want to avoid that step 3. to step 7. loop, you could always wrap steps 4. through 6. in a transaction, meaning every other attempt to save blocks until current save is resolved. This is pretty heavy handed and requires a bit more work and may effectively reduce overall concurrency.

Yet another possible solution

Another possible solution is to make the process less discrete and more continuous. Provide a live feed of data.

  1. Create a WindowsService/WCF Service that pushes or allows polling of table data,
  2. Page polls for data or asynchronously receives data from remote service,
  3. Page modifies user s page contents with received data
  4. New values that do not conflict are temporarily highlighted in one colour (indicating conflict-free change), say light green
  5. New values that do conflict are permanently highlighted in red

If you have a save process, no red values may be saved until resolved.

Last (suggested) possible solution

If you have no explicit save action,

  1. User clicks on a cell (effectively requesting to edit a cell)
  2. Page communicates to WindowsWCF service requesting a "lock" on that cell,
  3. If no other user has requested a "lock" on that particular cell, then lock cell to that user and return true. If another user has requested lock on that particular cell, then respect current lock and return false.

If remote service returns false, then use-case ends, and cell cannot be modified. If remote service returns true, then user modifies contents and when they leave the cell or reloads page or whatever, the remote service releases the lock.

Conclusion

Alright, a bit of hand waving, but more than enough fat to chew. Give it some thought, there are many possible solutions.





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签