Quantcast
Viewing all articles
Browse latest Browse all 12583

Load and Display data in a UltraGrid using Background Worker Thread

Image may be NSFW.
Clik here to view.


I have a requirement where I need to load data using a background worker thread and display on a grid (mentioned above in the pict) based upon  a column "Status" (highlighted in box). When I have observed the logic for populating the data I have found that CastNo with Status as "Closed" is taking too much time to load which eventually freezes the UI and users are always getting time out error. So I have written the logic in such a way that when user selects the cast with status "Closed,InspectionCompleted",Aborted"& Casting" I will first load the casts which are not in Closed status in the main thread and display the value in the grid. After that I will load the casts in a sep. BackgroundWorker thread and load the data at the end of the grid asynch. with out disturbing the UI. The issue I face is I am able to fetch values in different threads but Grid is not refreshing or loading data related to status "Closed" which is being fetched by a Background thread. Can someone please suggest me a solution .I am using MVP pattern for my project. Detailed explanation of the code is mentioned below.

First in MainView.cs I have a property as :

        ///


        /// place where cast is loaded in MainView.cs
        ///
        IList IMainView.CastDetailsComposites
        {
          get
          {
            return GridMaster as IList;
          }
         
          set
            {

              CastDetailsComposite currentSelection = _keopsGridMaster.GetSelectedEntity();
            
            _bindingSourceMaster.DataSource = value;

       

            }
        }

in My Main Presenter I have written the code as mentioned below.

  public class MainPresenter : MainPresenterBase
    {
    
      private readonly BackgroundWorker _backgroundWorkerCastProcess;
      private static IList _castresults;
    

      ///


      /// Parameterless constructor for CAB Constructor
      ///
      public MainPresenter()
      {
     
        _backgroundWorkerCastProcess = new BackgroundWorker();
        _backgroundWorkerCastProcess.DoWork += OnCastHistoryProcess;
        _backgroundWorkerCastProcess.RunWorkerCompleted += OnCastHistoryProcessCompleted;

      }

   

 //Method LoadData will be called when user click on "Search" button from the main screen.

         ///


        /// Coding for loading data with Casts which are in InspectionCompleted",Aborted" & Casting
        ///
        public override void LoadData()
        {
          
            try
            {

              //Below method fetches data from DB with status InspectionCompleted",Aborted" & Casting status .

            //This runs in the main UI thread

                View.CastDetailsComposites = Model.GetCastDetails(View.SelectedProductType,
                                                                  View.SelectedCastingCenter,
                                                                  View.SelectedAlloyCode,
                                                                  View.SelectedDimension, View.GivenCastNumber,
                                                                  View.StartDate, View.EndDate, View.SelectedCastStatusIDs);

  ///Running the Async worker here


                if (!_backgroundWorkerCastProcess.IsBusy)
                {
                  _backgroundWorkerCastProcess.RunWorkerAsync();
                }

                }
            }
            catch (Exception ex)
            {
              
                ExceptionManager.HandleException(ex, ExceptionPolicies.Presenter);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }

//Code for fetching Casts which are in "Closed" status this will be running the BackgroundWorker thread

   private void OnCastHistoryProcess(object sender, DoWorkEventArgs e)
        {
            try
            {
               ********************************************************************
                //Code for fetching data in the Background Worker thread.

             //I am storing the lists of Casts which are in Closed status in a List object : castresults
                _castresults = Model.GetCastDetailsClosed(View.SelectedProductType,
                                                                 View.SelectedCastingCenter,
                                                                 View.SelectedAlloyCode,
                                                                 View.SelectedDimension, View.GivenCastNumber,
                                                                 View.StartDate, View.EndDate, View.SelectedCastStatusIDs);
              
               

              
            }
            catch (Exception ex)
            {
              
                ExceptionManager.HandleException(ex, ExceptionPolicies.LogOnly);
            }
        }

//Finally I am assigning the list back to the view at the below method.

 private void OnCastHistoryProcessCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            // In case the screen was closed by the user before the operation completed.
            if (View != null)
            {
              View.CastDetailsComposites = _castresults;
              View.Refresh();
            }
        }

But what I am getting is even though the list castresults gives all the casts which are in Closed,InspectionCompleted",Aborted" & Casting status grid is not refreshed and I am always getting casts without "Closed" status. Can anyone suggest me whether I am doing something wrong here or any UltraGrid property or something I need to change to make sure that UltraGrid can accept the data in an async way.

Note: I have set the Property : DisplayLayout->LoadStyle as LoadOnDemand . but still I am not able to refresh the grid. Please provide me an answer at the earliest .I am on the verge of deadline.

Image may be NSFW.
Clik here to view.


























After loading Casts with Status which are not in Closed status I am trying to load the casts which are in Closed status which is not happening.

Regards

-pep




Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>