the problem it looks like to me is that your mediator is in the wrong place..... Well Ideally ... what you would want to to is hit this Head on... split off of your main thread on application start and spawn the "forms" thread from this one, sending in a reference to your Singelton, (you will need to probably make a special struct for this to pass in some additional info.. best to do this ahead of time, because you'll be adding to this struct)...
program
{
main()
{
thread UI;
singeltonWrapper package = new SingeltonWrapper(new singelton());
Hidden((object)package);
this.spawn_worker threads();
}
}
once youve done this, put your (generic?) collection lets say
Dictionary<int,>
add this to your base class :
class baseclass{
Dictionary<int, file> yourDictionary;
}
and add this back into your wrapper in the creator...
now you pump all info to and from your mediator...
add a few accessors and getters, and have them speak with events on the form, spawning your threads from your base class thread.... NOT your UI thread..
also remember to put sleep(1)'s in where appropriate to allow your UI thread to refresh... alternatively at intervals to a status.join(approach, not in a declared namespace) to pull back state data....
at least that is how I've done it in the past...
AS per your questions:
Nick Reshetinsky wrote:
So each DownloadUnit object I create, I then add an event handler from ControlsManager method. So all DownloadUnit objects have the same event handlers. Is it a reason of my slow UI updating because each thread applies to one method?
shouldn't be, because the method is copied out to each thread... if however you are still concerned you can test this by:
your_event_Handeler(blah)
{
int hold = thread.ID;
if(hold!=thread.ID){throw new exception ("threads are all using the same block of code");
}
it may take a wile for this to throw.. but you can do this while debugging to double check..
if it does use critical region over the bulk of the method, that should fix the problem
Nick Reshetinsky wrote:
I plan to create some list of DownloadUnitHandler inside
a ControlsManager for each DownloadUnit so each downloading thread can have it's own copy of event handlers.
Is it corrective? Can you please advice something beter?
shouldn't need to... just manage your memory (mutex) carefully and that should take care of everything...
Hope this gets you on the right path.. Cheers. :cool: