I've been building a console application which I've recently decided to stick a WinForm GUI onto. This is being done in Visual Studio 2015 (C# 6.0, .NET Framework 4.5.2)
I've got the following project layout
|-Solution
|-- GUI (Windows Application)
|-- DoStuff1 (Class Library)
|-- DoStuff2 (Class Library)
|-- DoStuff3 (Class Library)
|-- ConsoleApp1 (ConsoleApp)
|-- ConsoleApp2 (ConsoleApp)
|-- Helpers (Class Library)
The problem now is that although it works functionally, it could end up taking a fair amount of time processing so I've started to look at using a BackgroundWorker, however all searches so far have shown how to use this when all processing/work is being done in the same Windows Application project, not if they have been separated.
Also, how would I go about reporting progress back from my class library back to my GUI, something to do with ReportProgress but just not sure how to set it up...
Is this possible, or do I need to move all of the code our of the class libraries and into the GUI project?
It is better to use Task.Run
to offload work to a background thread as it is more flexible and easier to compose with other work than BackgroundWorker
.
You can use the IProgress<T>
to report progress to the gui, this blog post shows an example of how to do that and compares it to using BackgroundWorker
.