Hi,
My application needs to run without any window poping up. Also the application needs to detect the shutdown from computer. Based on the input from this forum, i have used a form in the appliction. But i want this form to be hide from the user. Is there a way to activate the form and hide it?

Recommended Answers

All 9 Replies

I would personally prefer a console application, not windows application. If you have main logic code extracted outside of form, you can easily put together a console app.

However I do expect WinForm to have .visible = False possible. Problem is on what event of the form are you expecting your code to run? May be form load?

I would personally prefer a console application, not windows application. If you have main logic code extracted outside of form, you can easily put together a console app.

However I do expect WinForm to have .visible = False possible. Problem is on what event of the form are you expecting your code to run? May be form load?

yes on form load , ill run my code
but how to do that . I have multiple files .
( i was trying with consol application only, but a requriement came to detect the shutdown , which caused me to make the project to a form one)

I have a problem here

public partial class frmdualconection : Form
 
    {
        private const int WM_QUERYENDSESSION = 0x0011;      //Shut down
        
        public frmdualconection()
        {
            InitializeComponent();

        logicalflow();
           
        }
       public bool isShuttingDown = false;
     
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM_QUERYENDSESSION)
            {
         
                isShuttingDown = true;
            }
            base.WndProc(ref m);
        }

    }

In the logicalflow() function, i have a while loop which checks for some condition. When the logicalflow() is running and a shut down comes, the program is not detecting the shutdown.

Also how to write an event on form load. I cannot find it from pull down menu as in vb.net

Any input is appreciated

The easiest way to create a form load event handler is to doubleclick the form in design mode.
You don't have to use a Form or Console application, you can also start from an Empty project, but in that case you are responsible to fill in everything yourself.

Unless your application is threaded, a while loop will lock the application. Each time your form processes an event it will run all code associated with that event. Any other events will wait in the message queue until the code finishes. If you have an event which contains a while loop waiting for some condition to occur, then that event will not finish processing until the conditions are met. Until that happens, the other events are not processed.

Depending on the conditions you are waiting for, you may want to look at replacing the while loop with a custom event, or place it in a seperate thread so that it doesnt lock up execution.

Ye , i find that the while loop is causing me problem

try
            {

                readtext = readroutetable();                                           
                path = "d:\\madavas1.txt";
                deletefiles(path);                                      
                createfiles(path);                                     
                regMatch = "Persistent Routes:";
                Persistentroute(regMatch, readtext);                        
          persistantfilepresent = checkpersitantroute();                 
      if (persistantfilepresent == true)
                {
                    createpermanentfile();
                }   
                readzainrange();                                               
       readmadarange();                                       
                do
                {
                    [I]path = "d:\\madavas2.txt";
                    deletefiles(path);                                    
                  createfiles(path);                                                          
                    readtext = readroutetable();                                  
           regMatch = "Active Routes:";
                    ActiveRoutes(regMatch, readtext);                
                    Thread.Sleep(1000);                     // sleep the application for 1 second
                   currentgateway();                                    
                  
                    statuszain = comparerangeforzin();                         // 
                    if (statuszain == true)
                    {
                        statusmada = comparerangeformada();                     // 

                    }
                    if (statusmada == true)
                    {
                        break;
                    }[/I]                } while (statusmada == false);/

Now how to move this to a thread, so that the shut down comes, i can catch that ?

The easiest way to create a form load event handler is to doubleclick the form in design mode.
You don't have to use a Form or Console application, you can also start from an Empty project, but in that case you are responsible to fill in everything yourself.

If i have done the things in an empty project, how can i catch the system shut down?

Is there a way i can make the program to work such that the consol window runs in minimised way or rather hidden way. ie the screen is not shown?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.