WinApp Form Loads Too Much Data During a Load Event

I have a form that loads quite a lot of data from an SQL server. Below is the code that will give some good advice:

private void BranchCenter_Load(object sender, EventArgs e) {
  //Combo boxes:
  LoadCities();
  LoadCoordinators();
  LoadComputerSystems();

  //Actual entity
  LoadBranch();
}

private void LoadCities() {
  //LINQ2SQL to load data. ~5000 records.
}

private void LoadCoordinators() {
  //LINQ2SQL to load data. ~50 records.
}

private void LoadComputerSystems() {
  //LINQ2SQL to load data. ~550 records.
}

private void LoadBranch() {
  LoadBranchInit();
  LoadBranchDetails();
  LoadBranchTimings();
  LoadBranchServices();
  LoadBranchLocumsHistory();
  LoadBranchJobs();
  LoadBranchNotes();
}

private void LoadBranchInit() {
  //LINQ2SQL to load the Branch object based upon the Branch ID
}

private void LoadBranchDetails() {
  //LINQ2SQL to load basic branch stuff. 38 fields. Mixed editors.
}

private void LoadBranchTimings() {
  //LINQ2SQL to load timings info into 80 date-time controls
}

private void LoadBranchServices() {
  //LINQ2SQL to load services offered at branch info into 20 check-boxes controls
}

private void LoadBranchLocumsHistory() {
  //LINQ2SQL to load branch history info into grid control. Always increasing # of rows :(
}

private void LoadBranchJobs() {
  //LINQ2SQL to load branch jobs info into grid control. Always increasing # of rows :( 
}

private void LoadBranchNotes() {
  //LINQ2SQL to load branch notes info into grid control
}

The user interface is a form with tab controls. each part on top goes to the tab. I need to download and show the form to the user as quickly as possible. as soon as the form is shown, I need to run a series of background workers to get data for each page.

I tried to get confused with the background worker, but could not understand its use. I get the message that "another thread tried to access control on your main thread ... or something like that ..."

, , .

? .

+3
10

BackgroundWorker . RunWorkerAsync() .

DoWork , , Result DoWorkEventArgs .

. DoWork , . Result.

RunWorkerCompleted , DoWork, Result RunWorkerCompletedEventArgs. , , .

+1

, , . , , , , .

BackgroundWorker . . , , Visible = false, , ", , ...". , , . , - , , .

+3

, .

.

, , , .

, , , , , .

+3

, DoWork BackgroundWorker .

BackgroundWorker.ReportProgress( int progress, object state) GUI, .

, GUI, .

+1

, ; . , , Invoke. .

+1

, BackgroundWorker .

, , DoWork.

e.

RunWorkerCompleted e.Results .

+1

TabControl .

UserControl.

+1

, , , . , UI, Control.Invoke, .

0

. . . link-2-link, Reactive Extensions .NET(Rx). ? Rx .

0

, . Visual Studio 2010 Task.Factory.StartNew(() = > myMethod());

, :

private void LoadLocum() {
    var TaskInit = Task.Factory.StartNew(() => LoadLocumInit());
    TaskInit.Wait();

    var TaskDetails = Task.Factory.StartNew(() => LoadLocumDetails());
    TaskDetails.Wait();

    var TaskQualifications = Task.Factory.StartNew(() => LoadLocumQualifications());
    //Enable Qualification TabPage automatically whenever TaskQualifications is complete

    Parallel.Invoke(
        () => LoadLocumComputerSystems(), 
        () => LoadLocumOtherInfo(), 
        () => LoadLocumEmergencyContacts(), 
        () => LoadLocumDistanceRates(), 
        () => LoadLocumDocuments(), 
        () => LoadLocumNotes(), 
        () => LoadLocumBannedStatus()
    );

}

() . . . , .

0

Source: https://habr.com/ru/post/1790708/


All Articles