dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online Membersbaskar
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Resources » Code Snippets » Console Applications

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


Posted Date:     Category: Console Applications    
Author: Member Level: Gold    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();
}
}
}
}
}







Did you like this resource? Share it with your friends and show your love!


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

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: How to add rich user experience by customizing your Console Window?
    Previous Resource: Detect network settings in a web page
    Return to Resources
    Post New Resource
    Category: Console Applications


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    (No tags found.)



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.