?
Solved

Interfaceless Application - How to keep it running

Posted on 2006-06-16
6
Medium Priority
?
369 Views
Last Modified: 2008-02-26
My past experience has always dealt with applications that have some sort of UI.  Hence, the application would run as long as the main form was left open.

I am now building an application that requires no UI.  It will run as a background application with a NotifyIcon to allow the user to end it, if necessary.

My question:  What is the technique used to keep a UI -less application running?  I currently have a module that has a Sub Main() which, at the moment, runs through some logic and then ends the application.  The application is supposed to poll a dBase 5.0 table for new records and perform some task when the appropriate records are added to the table.

I thought of using a loop, but don't want to consume 100% of the CPU while this is running.  I thought of using a timer object, but wouldn't that go away if the Main() sub ended?

How can I get a UI-less application to remain in execution, polling the table every so often without consuming the majority of the CPU cycles?

Thanks
0
Comment
Question by:Edward Stevens
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 18

Expert Comment

by:Ravi Singh
ID: 16919681
Hi, have you come across Windows Services? They're typically run in the background without any user interface, check out for more info + tutorial:

http://www.developerfusion.co.uk/show/3441/ 

0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1000 total points
ID: 16920174
"It will run as a background application with a NotifyIcon to allow the user to end it, if necessary."

Inherit from the ApplicationContext() class...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsapplicationcontextclasstopic.asp

    "You can use the ApplicationContext class to redefine the circumstances that cause a message loop to exit."

Here is a complete example in VB.Net 2003:

(note the instructions in code on how to embed the Icon for your NotifyIcon)

Module Module1

    Public Sub Main()
        Application.Run(New MyContext)
    End Sub

    Public Class MyContext
        Inherits ApplicationContext

        Private ni As NotifyIcon
        Private ICO As Icon
        Private WithEvents mi As MenuItem
        Private WithEvents tmr As New System.Windows.Forms.Timer

        Public Sub New()
            ' build a NotifyIcon and display it
            ' The Icon is an embedded resource:
            ' Project --> Add Existing Item... --> Select your .ICO file
            ' In the Solution Explorer, select your .ICO file
            ' Down below in the Properites Pane,
            ' change the Build Action from "Content" to "Embedded Resource"
            ni = New NotifyIcon
            ICO = New Icon(Me.GetType, "unfazed.ico") ' the .ICO filename IS CASE SENSITIVE
            ni.Icon = ICO
            ni.Visible = True

            ' make a context menu and assign it to our NotifyIcon
            Dim cm As New ContextMenu
            mi = cm.MenuItems.Add("Close Application")
            ni.ContextMenu = cm

            ' the polling loop
            tmr.Interval = 5000 ' (5 seconds) adjust to your liking...
            tmr.Start()
        End Sub

        Private Sub mi_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mi.Click
            ni.Visible = False
            ni.Icon = Nothing
            ICO.Dispose()

            Me.ExitThread()
        End Sub

        Private Sub tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmr.Tick
            tmr.Stop()

            ' do something in here...
            MessageBox.Show("Tick", "Polling...", MessageBoxButtons.OK, MessageBoxIcon.Information)

            tmr.Start()
        End Sub

    End Class

End Module
0
 
LVL 1

Author Comment

by:Edward Stevens
ID: 16920332
Idle,

If I understand the concept correctly, MyContext runs as a new, separate thread.  This is just what I'm looking for.  I'll test it tonight.

Thanks
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:Edward Stevens
ID: 16920345
Didn't want to leave Zephyr out.  Thanks for your suggestion.  It isn't what I'm looking for in this project but the info will be usefull for other projects.
0
 
LVL 18

Expert Comment

by:Ravi Singh
ID: 16920375
ok no probs! Thanks
0
 
LVL 1

Author Comment

by:Edward Stevens
ID: 16927406
Idle,

Worked perfectly.  Thanks for the help.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

771 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