views:

62

answers:

3

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?

A: 

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.

ctacke
Thanks for your reply. The problem I have is that when I minimize the Form (using the [X] in the upper right corner), the phone would crash and requires a restart of the phone. And I am not pretty sure what's the other option you mentioned about, could you explain it more detail?Thanks a lot!
If minimizing your app causes a crash then you need to debug and fix that issue, not try to find some other workaround.
ctacke
A: 

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.

Ram
+1  A: 

How about creating a Service instead of a background worker?

MasterGaurav