Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Automatically Starting Your Application on Windows Mobile

, 31 Jul 2008
An article discussing the various methods that you can use to automatically start an application on Windows Mobile, either by schedule or in reaction to a system event.
WiMoAutoStart_Source.zip
ShowCommandLine
bin
Debug
ShowCommandLine.exe
Win32.dll
Properties
ShowCommandLine.csproj.user
TimedStart
bin
Debug
TimedStart.exe
Win32.dll
Properties
TimedStart.csproj.user
WakeUpStart
bin
Debug
WakeUpStart.exe
Win32.dll
Properties
WakeUpStart.csproj.user
Win32
bin
Debug
Win32.dll
Properties
Win32.csproj.user
using System;
using System.Linq;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using Win32;

namespace ShowCommandLine
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [MTAThread]
static void Main(string[] args)
{
    IntPtr eventHandle = IntPtr.Zero;
    const string ApplicationEventName = "ShowCommandLineEvent";  //We will use this as our handle to 
                                                                 //to ensure only one instance of the
                                                                 //program is started            
    try
    {
        //Try to create the event.  If the creation fails then it is 
        //because another instance of this application is already 
        //running. If another instance exists then this instance
        //should immediatly terminate.
        eventHandle = CoreDLL.CreateEvent(IntPtr.Zero, true, false, ApplicationEventName);
        int lastError = Marshal.GetLastWin32Error();
        //MessageBox.Show(String.Format("event handle {0}",eventHandle));
        
        if (0 == lastError)
        {
            Form1 form = new Form1();
            form.Args = args;
            Application.Run(form);
        }
    }
    finally
    {
        //When the application is no longer running it should release the event
        if (eventHandle != IntPtr.Zero)
            CoreDLL.CloseHandle(eventHandle);
    }
}
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Joel Ivory Johnson
Software Developer Razorfish
United States United States
I attended Southern Polytechnic State University and earned a Bachelors of Science in Computer Science and later returned to earn a Masters of Science in Software Engineering.
 
For the past few years I've been providing solutions to clients using Microsoft technologies for web and Windows applications.
 
While most of my CodeProject.com articles are centered around Windows Phone it is only one of the areas in which I work and one of my interests. I also have interest in mobile development on Android and iPhone. Professionally I work with several Microsoft technologies including SQL Server technologies, Silverlight/WPF, ASP.Net and others. My recreational development interest are centered around Artificial Inteligence especially in the area of machine vision.
 
Follow on   Twitter

| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 31 Jul 2008
Article Copyright 2008 by Joel Ivory Johnson
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid