Run a C# .NET Compact Framework Application in Background

Posted on 2008-09-30
Last Modified: 2013-11-17

I am writing a SMS/Contact backup application, it need to run in the background (may be with an icon in the notification area)? What can I do to achieve it? Say FormBackup need to stay in memory, with a timer, that checks for new SMS etc and does the backup. How can I prevent user from clicking the X button to close it, and only Hide the form.

Question by:retinax
  • 2
  • 2
LVL 15

Expert Comment

ID: 22603783
In your Form_Load put the following:

            this.ControlBox = false; // Hides the minimize, X etc at the top of your form
            this.Hide();             // Will hide the form

Author Comment

ID: 22603898
Ok cool, thanks.

Any idea on the Notification area icon thing?

LVL 11

Expert Comment

ID: 22613698
Create NotifyIcon and ContextMenuStrip controls on the form.
Set setNotifyIcon's ContextMenuStrip property to your context menu.
Set NotifyIcon's Icon property to icon of your choice and set it's Visible property to true.
Create a 'Show form' menu in your context menu strip and fill it with this code:

        private void showFormToolStripMenuItem_Click(object sender, EventArgs e)


            this.WindowState = FormWindowState.Normal;

            this.Visible = true;


Open in new window


Author Comment

ID: 22615125
Thanks, are those controls available only in WM6 professional sdk not standard edition??
LVL 11

Accepted Solution

dbrckovi earned 400 total points
ID: 22615959
I'm sorry for wrong information. I didn't see you were programming in Compact framework.
However you can download notifyicon example for Compact Framework from this page:

Unfortunately I didn't manage to make it show the icon in Pocket PC emulator, but maybe it will work on other version of OS's or on a real device.

You can use it in your project by importing NotifyIcon.cs file, adding reference to Microsoft.WindowsCE.Forms, and using code in code snippet.

I hope this helps.
        private NotifyIcon notifyIcon;


        public Form1()



            notifyIcon = new NotifyIcon();

            notifyIcon.Click += new EventHandler(notifyIcon_Click);


        private void button1_Click(object sender, EventArgs e)


            IntPtr hIcon = LoadIcon(GetModuleHandle(null), "notify.ico");




        private void button2_Click(object sender, EventArgs e)





        internal static extern IntPtr LoadIcon(IntPtr hInst, string IconName);


        internal static extern IntPtr GetModuleHandle(String lpModuleName);

        private void notifyIcon_Click(object sender, EventArgs e)


            MessageBox.Show("Icon Clicked!");


Open in new window


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now