I want to upload a file in a class that does not know about the form where the progress of the upload shoul be visible. Is there a way through events or delegate to inform it somehow?
at this moment I can set the progress directly, but I want to do the class lesser dependent on the view implementation.
thanks
I want to upload a file in a class that does not know about
Share
Definitely. You will need to implement some sort of “ProgressMade” event on the uploading class, which the form will then subscribe to (or be subscribed to by some intermediary like a Controller if that’s your pattern). You should then raise the “ProgressMade” event when your class detects that data has been sent.
How THAT happens depends on what your class is using to perform the upload. If you’re using a StreamWriter, unfortunately those classes don’t have “reactive” events that monitor progress. All is not lost; you should be able to derive from the class you’re using to fire a “WritePerformed” of some sort that you can use to trigger ProgressMade. Check out this answer: how to increase progressbar when i write xml?. It should apply to pretty much any Writer. If you’re using something a little less abstract, like a Socket, then you should be well able to track the number of bytes you’re pushing into the connection.