Dear All, I'm thinking events... Dear Mikael,IF I start multiple instances of a class that I need to contact while it's runni
Project....
A VB.Net exe that when running starts multiple instances of a class, the worker class has the job of at given intervals move and adjust contents of some text files.
No I need to be able to from one form see how the class is processing, what it has processed.
How can I do this.
example...
Start exe..
create 3 instances of the worker class.....
Worker class runs and is doing it's job as definned.
User selects from a list provided a job instance to see how it's doing
The exe should get contact with a method within the selected worker job/class and
the class should return some relevant information to a windows form.
The user should be able to even pause, stop the worker class if required.
any ideas ?
regards /PaulSv: IF I start multiple instances of a class that I need to contact while it's r
Provided I have understood what you are trying to do I would do something like this:
The worker class (marxist?) exposes one event that triggers on some kind of processing progress, like every 1000 row processed in the file.
This class has been definied and initialized from the main form. That form does not register for the event until the user has clicked a button that says something like "tell me how you are doing".
The clickevent adds a handler for the event in the working class and a sub or function processes it.
The working class:
<code>
Public event Processing()
Public funtion StartProcess()
' code here
' On some criteria met
raiseevent me.Processing
end function
</code>
The form:
<code>
private withevents wClass as workingclass
private sub btnStartProcess_Click(...)
wClass = new workingclass
wClass.StartProcess()
end sub
private sub btnHowYaDoin_Click(...)
addhandler wClass.Processing, addressOf me.HowAreTheWorkers
end sub
private sub HowAreTheWorkers()
messagebox.show("The workers are working")
removehandler wClass.Processing
end sub
</code>
All this requires you to start the wclass-process in a different thead and then implement it.
//Mikael SandSv: IF I start multiple instances of a class that I need to contact while it's r
Thanx for that, I was thinking about using threads as well, but my problem was then that at some point I want to kill the thread ( or at least the user would ) if not kill it then at least pause a timer that would be running on the worker ( as all workers would basically be looking in folder A for file type A and moving them to Folder B and logging all actions processed ). also I would want to give the worker new instructions if the user decide that the worker should look in another folder or for another type of file to process.
I got som einfo about having to cache the thread id or something, but I did not feel that comfortable with the idea. but if you got any sample code and are interested in sharing then I'l have a bash.
again thanx for good thoughts.
cheers Paul