Description of the problem : you are writing a library that contains some algorithms / tasks that can take a lot of time for various reasons: computing, file system, network communication, etc. You want to be able to:
- Send some information about the progress of the task (progress, activity logging, etc.).
- You have a way to abort the task before completion if any external signal or property has been set.
I implemented a structure for this, but it requires that all such tasks reference the assembly containing this structure.
My question is: is there already a built-in mechanism in the .NET framework (3.5 or lower) for the problem described above?
I know that I can use events, but that would mean that long-running tasks should expose events that, I think, are overhead. Ideally, I want to have a framework that hides multithreading problems and is dependency-friendly, but will not depend on an additional user assembly and will not pollute the original interface.
I hope I have described the problem well enough. If not, I can publish some sample interfaces from my own structure.
UPDATE : OK, I think a little clarification is needed for my description of the problem :). When I say "long-term," I do not mean "long" in the sense of a workflow. I am working on a WinForms mapping application that does all kinds of things, like creating contours of terrain . To do this, you first need to download the altitude data files from the FTP server, unzip them, and then perform some calculations. I wrote the code for this a long time ago, but in order to make it more convenient for the graphical interface, I need to perform a retro-check of various checks - for example, if I find that the user clicked the Abort button and stopped the process.
So, basically my concern is this: how to write code that later (if ever at all) will be used in a GUI environment, where you cannot just run everything in the main GUI thread and freeze the entire application. The challenge is to find a way to make your code suitable for GUI purposes without tying it to a specific GUI platform.
multithreading synchronization user-interface c # asynchronous
Igor Brejc
source share