Open DBF’s not visible in BackgroundWorker second thread.
Posted: Mon Apr 22, 2024 5:23 pm
Hello XSharpers;
Problem: open DBF’s not visible in BackgroundWorker second thread.
In my application, there is a utility that performs calculations on individual’s health benefit costs.
This calculation can take some time depending on how many individuals are being calculated, so In order to show some activity, in the Harbour-Clipper version, I would simply put the current individual’s Id up on the screen which took all of one line of code.
In Windows this is a much complicated affair (perhaps someone can direct me to a simpler approach than the one I've taken):
In my X# conversion, there is a ‘start’ button on the utilities’ form; at the time the calculation form is opened, I have about a dozen open DBF’s. My understanding is that, being Windows, once the calculation is started, the form never gets control again until the calculation has completed, so there is no simple way to update a label on the form.
So, I’ve been trying to use the BackgroundWorker widget (which I named "bgwUserID" to have the calculation run as a second thread. I set the BackgroundWorker’s DoWork() method to my main processing function named “DoCalculation()”; the ‘Start’ button initiates the BackgroundWorker's “RunWorkerAsync()” function. TheBackgroundWorker’s "ProgressChanged" method updates a label with the current individual's ID.
The open DBF's no longer appear inside the second thread. I assume I’m doing something wrong, but haven’t a clue, perhaps you can help.
PS: I can’t use a “Progressbar” because I don’t know ahead of time how many individuals will be in the calculation since it depends on the user’s selections.
My “Stack”:
Windows 11
VS 2022, Project template: “Harbour Console Application”;
Project references:
-Mscorelib
-System
-System.Core
-System.Data
-System.Data.DataSetExtensions
-Syste.Xml
-System.Xml.Linq
-XSharp.Core
-XSharp.Data
-XSharp.RDD
-XSharp.RT
-XSharp.RT.Debugger
-XSharp.SQLRdd
X# Ver 2.18.04
SQLExpress V 16.0.1000.6
Problem: open DBF’s not visible in BackgroundWorker second thread.
In my application, there is a utility that performs calculations on individual’s health benefit costs.
This calculation can take some time depending on how many individuals are being calculated, so In order to show some activity, in the Harbour-Clipper version, I would simply put the current individual’s Id up on the screen which took all of one line of code.
In Windows this is a much complicated affair (perhaps someone can direct me to a simpler approach than the one I've taken):
In my X# conversion, there is a ‘start’ button on the utilities’ form; at the time the calculation form is opened, I have about a dozen open DBF’s. My understanding is that, being Windows, once the calculation is started, the form never gets control again until the calculation has completed, so there is no simple way to update a label on the form.
So, I’ve been trying to use the BackgroundWorker widget (which I named "bgwUserID" to have the calculation run as a second thread. I set the BackgroundWorker’s DoWork() method to my main processing function named “DoCalculation()”; the ‘Start’ button initiates the BackgroundWorker's “RunWorkerAsync()” function. TheBackgroundWorker’s "ProgressChanged" method updates a label with the current individual's ID.
The open DBF's no longer appear inside the second thread. I assume I’m doing something wrong, but haven’t a clue, perhaps you can help.
PS: I can’t use a “Progressbar” because I don’t know ahead of time how many individuals will be in the calculation since it depends on the user’s selections.
Thanks for your help!PRIVATE METHOD btnCalc_Click(sender AS System.Object, e AS System.EventArgs) AS VOID STRICT
// DBFs are open
SELF:bgwUserID:RunWorkerAsync()
RETURN
END METHOD
PRIVATE METHOD bgwUserId_DoWork(sender AS System.Object, e AS System.ComponentModel.DoWorkEventArgs) AS VOID STRICT
// no DBF files apear as "open" at this spot
DoCalculation()
RETURN
END METHOD
My “Stack”:
Windows 11
VS 2022, Project template: “Harbour Console Application”;
Project references:
-Mscorelib
-System
-System.Core
-System.Data
-System.Data.DataSetExtensions
-Syste.Xml
-System.Xml.Linq
-XSharp.Core
-XSharp.Data
-XSharp.RDD
-XSharp.RT
-XSharp.RT.Debugger
-XSharp.SQLRdd
X# Ver 2.18.04
SQLExpress V 16.0.1000.6