Solved

Run a C# .NET Compact Framework Application in Background

Posted on 2008-09-30
6
4,040 Views
Last Modified: 2013-11-17
Hi,

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.

Thanks
0
Comment
Question by:retinax
  • 2
  • 2
6 Comments
 
LVL 15

Expert Comment

by:angus_young_acdc
Comment Utility
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
0
 

Author Comment

by:retinax
Comment Utility
Ok cool, thanks.

Any idea on the Notification area icon thing?

0
 
LVL 11

Expert Comment

by:dbrckovi
Comment Utility
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

0
 

Author Comment

by:retinax
Comment Utility
Thanks, are those controls available only in WM6 professional sdk not standard edition??
0
 
LVL 11

Accepted Solution

by:
dbrckovi earned 400 total points
Comment Utility
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:
http://www.microsoft.com/downloads/details.aspx?familyid=5a8384c0-34a5-47d1-bb50-e5e261288ae3&displaylang=en

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()

        {

            InitializeComponent();
 

            notifyIcon = new NotifyIcon();

            notifyIcon.Click += new EventHandler(notifyIcon_Click);

        }
 

        private void button1_Click(object sender, EventArgs e)

        {

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

            notifyIcon.Add(hIcon);

            this.Hide();

        }
 

        private void button2_Click(object sender, EventArgs e)

        {

            notifyIcon.Remove();

        }
 

        [DllImport("coredll.dll")]

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

        [DllImport("coredll.dll")]

        internal static extern IntPtr GetModuleHandle(String lpModuleName);
 

        private void notifyIcon_Click(object sender, EventArgs e)

        {

            MessageBox.Show("Icon Clicked!");

        }

Open in new window

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Log4Net custom Appender not being fired. 5 41
Using MS Code on my Mac 6 44
XML to SQL Table using c# 5 44
Paging GridView 7 32
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

10 Experts available now in Live!

Get 1:1 Help Now