c# - SignalR polling not always returning accurate database results -


In my app, I start an import process by uploading an XML file. After uploading it, a series of stored procedures run and the XML file is parsed, and the data is inserted into many different tables. As soon as its progress, a statistics table is updated to reflect the inclusive progress. The statistics table has 4 columns: batch id , batchcount , processcode , and errorCount . Batch count All records are counted if the records are properly inserted without any problems, then process count is increased by 1, if it fails then < Code> ErrorCount increases with 1. (These two columns are always changing during the import process)

My main goal is to display import progress using signal R. I have a hub method which is okay for voting, I am seeing the updated timestamps in the UI. However, this problem is that counting is always 0 (initial value), or sometimes it is sometimes read and looks like random 985. If it reads any value, it only does once and will not change it again. Here is my hub method:

  public void BeginPolling () {when (true) {var stats = _repository .GetImportStats (); Var message = "Preparing file ..."; If (statistics = zero) {message = DateTime.Now + "- Calculate:" + stats.processCount.ToString (); } Else {message = DateTime.Now + "- Stats returned results."; } // Displays a message on a UI on my UI client. Caller.show progress (message); // I have tried many sleeping times (1000, 5000, 10000) thread. Sleep (5000); }}   

Below is my _repository.getImportStats method, for testing purposes it only takes hold of the first (and only) records: < Pre> public statistics GetImportStats () {DataContext.Stats.FirstOrDefault (); }

In addition to testing, I tried to put a button on my UI which calls the same GetImportStats () method to an AJAX, And it always gives process work ok, so I think the problem is within my signal implementation implementation any help is appreciated!

You are doing one of the big frames of the unit framework, you have long lived DbContext Never should it.

In this case, you are having problems with the unit trackworches change tracker by default EF mergeption. The append uses only .

It means by default, on each EF query, EF will only drearize the rows to the object, the IFF key does not match any object Changes to the theme Tracker

So you have used the same example of each loop in EF reference, EF only when you query (SQL runs but does not make EF or uses cached values Object is expected to change)

You have several options to fix this.

  • Tell EF to use a new EF reference (and use MergeOption.OverwriteChanges on each track.
  • Change the EF Tracker AT Do not use ALL (this disables access, but is too fast).

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -