user329762
user329762

Reputation: 11

How to keep process running after closing the program?

I am now developing an application on Windows Mobile 6.5 with .Net Compact Framework 3.5 using C#. There is a function in the program that I use it to update the location information periodically from server side, but if I keep running this computation, it would cost too much energe. For this reason, I want to run it in background and I try to use BackgroundWorker to do this and it works well.

The problem I have now is that I can't minimize the program so that I have to keep the main form of the program run in foreground even if it's not doing anything and this is very inconvinence for a user. However, when I close the program, the BackgroundWorker will also be closed.

Is there any method to keep the update process running (somewhere in memory or so) when I close the program? and then can restore the information when I restart the program?

Upvotes: 1

Views: 1850

Answers (3)

gvaish
gvaish

Reputation: 9414

How about creating a Service instead of a background worker?

Upvotes: 1

Ram
Ram

Reputation: 11644

I have not used the .NETCF 3.5. However in the previous version on .NETCF 1.0/2.0 I observed that even if you close the application using (X) button, it just goes to background but remain in the memory.

If that is the case with .NETCF 3.5 as well then I think you do not need to anything here. The background worked will be running even if you close the application.

I Hope this will help you.

Upvotes: 0

ctacke
ctacke

Reputation: 67188

If your Form closes, then Application.Run (probably called over in Program.Main) returns and the process' primary thread exits, causing the application to terminate.

The solution, then, is don't close the Form, simply Hide it. By default the "MinimizeBox" property for your Form should have been true and it should have an [X] in the upper right corner. Clicking this minimizes the Form and will not exit your application.

The other option in some cases is to not have a Form at all. The challenge here is that the CF doesn't have any Application.Run overload that doesn't accept in a Form (like the desktop framework does). The Smart Device Framework does provide one if you want to go that route.

Upvotes: 0

Related Questions