C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Quick Console Utility to hide itself and do activities in the background


Posted Date: 12 Apr 2007    Resource Type: Code Snippets    Category: Console Applications

Posted By: Vasudevan Deepak Kumar       Member Level: Diamond
Rating:     Points: 10



Many a times our applications (desktop applications) need automatic updations. The best recommended way is to have BITS API used. For very small applications, a quick console application that checks for updates, does updation and then starts the main application is a good trick.

Here is one such humble endeavor where a console application starts up and hides itself. The actual logic of updation is just a sleep for some time and then confirm back to the user that updates are complete. The launch of main (parent) application here is to just exit the console application.



using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;

namespace ConsoleApplication1
{
///
/// Summary description for Class1.
///

class Class1
{
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName,string lpWindowName);

[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);


///
/// The main entry point for the application.
///

[STAThread]
static void Main(string[] args)
{
string strAppName = "\""+AppDomain.CurrentDomain.BaseDirectory+AppDomain.CurrentDomain.FriendlyName+"\"";
IntPtr hWnd = FindWindow(null,strAppName);
if (hWnd != IntPtr.Zero)
{
ShowWindow(hWnd,0);
if (MessageBox.Show("There are updates. Proceed?","Update Confirm",MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.No)
{
return;
}
else
{
ShowWindow(hWnd,0);
Thread.Sleep(5000);
MessageBox.Show("Updates are complete","System Update",MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.Exit();
}
}
}
}
}






Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to add rich user experience by customizing your Console Window?
Previous Resource: Detect network settings in a web page
Return to Discussion Resource Index
Post New Resource
Category: Console Applications


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use