VBobCat
Well-known member
Hello people,
I'll explain this theoretically because I feel I need some conceptual guidance before coding.
My application manages bureaucratic flow of paper documents, in order to distribute them to the due personal which has to deal with them.
The main user has a huge pile of papers, and he does his duty by entering from each paper its serial number, and the names and/or ID numbers of people involved and mentioned in it.
The system registers the paper and distributes it to one member of the staff responsible to give the paper further analysis, using an algorythm that provides random and balanced distribution, in order every member gets moreover the same amount of work at the end of the day.
Some of the work of these people, then, demands internet researching for collection of data related to people mentioned in those papers content.
This resarch is done simply filling the ID number of those people into a series of websites, in order to get additional information about them, and then collect and register this information, and them perform some decision considering all that.
So these people came to me and asked me to include in my application an antecipated and automated research of that data, which I am actually able to do, using WebBrowser automation.
But there's a dilemma in it. Each web query will take some time, let's say 5 to 30 seconds to complete, and it depends on the speed of external websites, that can be rather fast one day, and annoyingly slow another.
In the other hand, I cannot insert this extra waiting time between each time the responsible user types the number and basic data of each paper, because if I did, what now takes half an hour would take four hours, and this user actually has other pieces of work to do besides feeding data into my system.
So I thought I could do this:
I was thinking I should have a single frame class that does the interface between the routine that is entangled with the UI, and the multiple query classes would be seen only by this frame class.
So I would first create it, by doing this:
Each time a new paper is registered, the form summons that frame class to do the query:
So this class would be something like this (this is just a stub):
But then, again, after writing this stub, IntelliSense put the code below in curly-blue-underline:
Invoke(AddressOf MyParallelQueryFrameClass.QueryPerson, PersonID)
and said:
'AddressOf' expression cannot be converted to System.Delegate because type 'System.Delegate' is declared 'MustInherit' and cannot be created.
At this point, I'm running short of knowledge. I'd be grateful if anyone could put this plain and straight for me to understand it.
And of course, I'm already grateful for the patience of those who managed to read it all until here.
I'll explain this theoretically because I feel I need some conceptual guidance before coding.
My application manages bureaucratic flow of paper documents, in order to distribute them to the due personal which has to deal with them.
The main user has a huge pile of papers, and he does his duty by entering from each paper its serial number, and the names and/or ID numbers of people involved and mentioned in it.
The system registers the paper and distributes it to one member of the staff responsible to give the paper further analysis, using an algorythm that provides random and balanced distribution, in order every member gets moreover the same amount of work at the end of the day.
Some of the work of these people, then, demands internet researching for collection of data related to people mentioned in those papers content.
This resarch is done simply filling the ID number of those people into a series of websites, in order to get additional information about them, and then collect and register this information, and them perform some decision considering all that.
So these people came to me and asked me to include in my application an antecipated and automated research of that data, which I am actually able to do, using WebBrowser automation.
But there's a dilemma in it. Each web query will take some time, let's say 5 to 30 seconds to complete, and it depends on the speed of external websites, that can be rather fast one day, and annoyingly slow another.
In the other hand, I cannot insert this extra waiting time between each time the responsible user types the number and basic data of each paper, because if I did, what now takes half an hour would take four hours, and this user actually has other pieces of work to do besides feeding data into my system.
So I thought I could do this:
- Each time user registers one paper, my application would invoke a routine to run once for each website that needs to be queried;
- This routine, I think, should be a class, and this class:
- Must be created out of the UI thread, preventing it to halt;
- Has a constructor which takes a number (this number is the key for further querying) as argument;
- Creates its own WebBrowser object to do its bidding;
- Handles the DocumentCompleted event of this WebBrowser and collects the data it returns;
- Writes this data into the database;
- Signals when finished.
- As the user continues to register papers, new classes are created out of the UI thread, even if the previous ones didn't finish their job;
- All the routine inside UI thread has to do is monitor if there are active classes still working, in order to prevent user to close application before all of them are finished.
I was thinking I should have a single frame class that does the interface between the routine that is entangled with the UI, and the multiple query classes would be seen only by this frame class.
So I would first create it, by doing this:
VB.NET:
Dim MyParallelQueryThread As New System.Threading.Thread(AddressOf MyParallelQueryFrameClass.Prepare)
MyParallelQueryThread.Start
VB.NET:
Dim PersonID as Long = Long.Parse(TextBoxPersonID.Text)
Invoke(Addressof MyParallelQueryFrameClass.QueryPerson, PersonID)
Friend Class MyParallelQueryFrameClass Shared Queries As List(Of WebQuery) Shared Sub Prepare() Queries = New List(Of WebQuery) End Sub Shared Sub QueryPerson(PersonID As Long) Queries.Add(New WebQuery("Person", PersonID)) End Sub Shared ReadOnly Property AllFinished As Boolean Get Return (From WQ As WebQuery In Queries Where WQ.Active Select WQ).Count = 0 End Get End Property Class WebQuery Friend Active As Boolean Private WithEvents WB As WebBrowser Sub New(QueryType As String, QueryArgument As Object) Active = True If QueryType = "Person" Then WB.Navigate("http://www.personqueryuponid.sample.br") End If End Sub Private Sub WB_DC(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WB.DocumentCompleted 'read html document 'if it is query form: ' - fill the proper fields and submit; 'end if 'if it is query response: '- collect and write info into database Active = False 'end if End Sub End Class End Class
But then, again, after writing this stub, IntelliSense put the code below in curly-blue-underline:
Invoke(AddressOf MyParallelQueryFrameClass.QueryPerson, PersonID)
and said:
'AddressOf' expression cannot be converted to System.Delegate because type 'System.Delegate' is declared 'MustInherit' and cannot be created.
At this point, I'm running short of knowledge. I'd be grateful if anyone could put this plain and straight for me to understand it.
And of course, I'm already grateful for the patience of those who managed to read it all until here.