Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a VB.Net tray app to single-instance if Application Framework is disabled?

Tags:

vb.net

I would like to create a VB.Net tray app that launches directly to the tray, instead of being sent there by a hidden startup form. I found a CodeProject article that explains how to do this, and it works perfectly. It describes how to disable the Application Framework (and then re-enable it later), so the startup object can be set to a module with the startup code.

But after the Application Framework is re-enabled, how do I programmatically enable "Make single instance application"..?

Since the framework is initially disabled, all of its checkboxes are also disabled, including the one for single instance. I checked in both of the following namespaces, and could not find any property named "SingleInstance", or anything similar or seemingly related:

System.Windows.Forms.Application
System.Windows.Forms.ApplicationContext

So how can it be done?

For reference, here is the article:

http://www.codeproject.com/Articles/75822/Create-a-System-Tray-Application-in-VB-NET

like image 453
spinjector Avatar asked Nov 29 '25 15:11

spinjector


1 Answers

You cannot find a "SingleInstance" property or anything similar because it does not exist. The concept of single instance is compiler magic that the visual basic compiler adds for you when you check the "Make single instance application..." box in your project properties. If you want to use the visual basic magic with a tray only application, you'll need to manage several parts of the startup code yourself.

You'll need two pieces of code to make this work.

  1. Inherit from Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase and override the OnRun method. You'll create the tray app here using the methods of WindowsFormsApplicationBase to help.

  2. A Sub Main entry point for the application which creates an instance of your application base and calls the OnRun method.

You can read this article for more information on how the WindowsFormsApplicationBase works.

like image 59
just.another.programmer Avatar answered Dec 02 '25 04:12

just.another.programmer