Exit program in vb .net (application.exit)

Posted in Visual Basic .NET at 2:20 pm by

What methods are there?

  • System.Windows.Forms.Application.Exit() – Informs all message pumps that they must terminate, and then closes all application windows after the messages have been processed. This method stops all running message loops on all threads and closes all windows of the application. This method does not force the application to exit. The Exit method is typically called from within a message loop, and forces Run to return. To exit a message loop for the current thread only, call ExitThread. This is the call to use if you are running a WinForms application. As a general guideline, use this call if you have called System.Windows.Forms.Application.Run.
  • System.Environment.Exit(exitCode) – Terminates this process and gives the underlying operating system the specified exit code. This call requires that you have SecurityPermissionFlag.UnmanagedCode permissions. If you do not, a SecurityException error occurs. This is the call to use if you are running a console application.
  • End – (Visual Basic only) Terminates execution immediately. The End statement can be placed anywhere in a procedure to end code execution, close files opened with an Open statement, and clears variables at module and class level and all static local variables in all modules. The End statement calls System.Environment.Exit. The End statement stops code execution abruptly, without invoking the Finalize method or any other Visual Basic code. Object references held by other programs are invalidated. The End statement provides a way to force your program to halt. For normal termination of a Visual Basic program, you should unload all forms. Your program closes as soon as there are no other programs holding references to objects created and no code executing.

I want to close the application and I want to close it now

For instance you are handling an exception yourself and want the program to terminate immediately. Then you should do it with Environment.Exit(0)

You would like to exit your windows form based application in a clean way.

You are calling the routine from a menu item. You should use application.exit


Installing programs without a package manager.

Posted in Debian, Linux at 10:44 pm by

Installing programs without a package manager.

I have been a webmaster for about two years now. But webmaser doesn’t really describe my level of proficiency with managing a linux server.
Truth be told, I got my linux server with LAMP on it out of the box. So I had to install very little on it. It’s a webserver not a desktop.
And when I had to install stuff manually I just wgeted the tar file which was needed, prayed to the gods that be, and did the configure, make and make install.

Now I have a new web server and I’m installing it from scratch and while I was installing some un named obscure software. My friend, which I ‘ll hereafter refer to by the name of Payne, was watching my shell session so he could aid me. And when I did my configure, make, make install routine he uttered NOooooooooo. Turns out that installing it like that is just a bad practice. Many of the thousands of people who ‘ll read this will frown and be slightly stunned, isn’t that how most of the people are doing this?

The good

You should download the source do a

Explaining the debuild process is a bit large so I won’t get into it, but to summeraize it:
When you look at your software and you see a debian directory then it has already everything which is needed to turn it into a package with debuild.
You just launch debuild and when everything goes well you get a debian package in the parent directory.

The Bad

make install

What makes this bad is that you bypass the package management system. Which means that package management doesn’t know about the
software you just installed. Later on you can install the same software through the packet manager. Then you end up with 2 versions in 2 different locations. The make install method doesn’t take care of dependencies. When you want to uninstall libraries which your make install software depend on
you will get no warning. After you uninstalled it, you will be baffled to find out your ‘make install’ software stopped working. Last problem with this method is uninstalling of the software itself. Other software can depend on it. So when you uninstall this software you can run into the same trouble as mentioned before.

The Ugly

configure –sysconfdir=/etc –prefix /usr/xx
checkinstall -D make install

Answer the question ‘The package documentation directory ./doc-pak does not exist.
Should I create a default set of package docs? [y]:’ with ‘y’ .
Enter a description for your package.
Fill in what you like, need. In the end press enter to continue.

Your software is installed and a Debian package is created, you can find in the installation directory.
You can use this package on other pc’s
dpkg -i /path/to/software.deb

Uninstalling can be done by call the dpkg with -r parameter.

dpkg -r the_software

This is the ugly way because your package does not come with dependency checks nor does it come with our of the box init scripts.


Fix for iTunes 5002 Error

Posted in Miscellaneous at 4:11 pm by

Since upgrading to iTunes 7.3, I got the following error when searching iTunes Store for songs: “We could not complete your Music Store request. An unknown error occurred (5002).”

This problem is related to the iTunes shopping cart. To fix, go to edit/preferences/store, activate one-click shopping and press OK. The problem should now be fixed. If you want, you may also now re-enable the shopping cart.


Restarting services from a batch

Posted in windows at 2:33 pm by

When some of your servers are running services which leak memory, you’ll find yourself in the position where you are restarting these services all the time. A good admin will get tired off this very soon and look for a way to automate this.
Automating this is very easy. You can use the windows scheduled tasks to run a bat file.

The bat file has to contain something similar to this:

net stop "ASP.NET State Service"
net stop "FTP Publishing Service"
net stop "ReportServer"
net stop "World Wide Web Publishing Service"
net stop "Simple Mail Transport Protocol (SMTP)"
net stop "IIS Admin Service"

net start "IIS Admin Service"
net start "Simple Mail Transport Protocol (SMTP)"
net start "World Wide Web Publishing Service"
net start "ReportServer"
net start "FTP Publishing Service"
net start "ASP.NET State Service"

When restarting theses services you must lookout for dependencies tho. For instance in the above bat file the World Wide Web Publishing Service depends on the IIS Admin Service. this means you can’t restart the IIS admin Service when the World Wide Web Publishing Service is still running.