Nowin icon indicating copy to clipboard operation
Nowin copied to clipboard

Is it possible to provide a background worker sample?

Open robertkraig opened this issue 7 years ago • 3 comments

I've written an application which is form-based, it does some interval updates, I wanted to know if it's possible to provide an example of what it would look like to configure this application to use a BackgroundWorker such that the webserver could run in background while in a WinForm application.

robertkraig avatar Jun 23 '17 18:06 robertkraig

My objective is to host some simple binary image file for an IoT Node Application.

robertkraig avatar Jun 23 '17 18:06 robertkraig

Just look at NowinSample/Program.cs it cannot be much easier than that.

Bobris avatar Jun 23 '17 19:06 Bobris

If I understood your question correctly - you don't even need to use BackgroundWorker. Once you've created and started a server (see NowinSample/Program.cs as @Bobris mentioned) it will run until either stopped or disposed (so keep a reference alive, stop+dispose when no longer needed). Nowin uses external threads (simplified a bit, don't recall if there is an option to flow execution context) to handle requests. This however might require additional care when dealing with forms and controls - namely something like this:

if (control.InvokeRequired) 
{
    control.Invoke(()=>...action...);
}
else 
{
    ...action...
}

marius-klimantavicius avatar Jun 26 '17 06:06 marius-klimantavicius