Question Increment or Rename Each Instance of my Program

digitaldrew

Well-known member
Joined
Nov 10, 2012
Messages
167
Programming Experience
Beginner
Is it possible for me to automatically increment (or completely rename) each instance of my program which is opened and shown in the taskbar?

For example...A user wants to open 3 separate instances of my program. If he does right now all three instances will just show "Widget Program" when hovering over them in the taskbar. Would it be possible to have each one say "Widget Program [1]," "Widget Program [2]," and "Widget Program [3]"? Or even have the ability to allow them to rename each one?

Thanks!
 
One idea is to check running processes and change window text accordingly, something like:
        Dim p = Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName)
        Me.Text &= ":" & p.Count.ToString

A problem with this is if you for example open two, close the first one, then open another - by current count you will now have two instances labeled ":2".

A different idea is to have a user setting in application (My.Settings) that you increment each time application is started, and only when last instance is closed you can reset it to 0. Here is example for Form Load event:
        My.Settings.pincrement += 1
        My.Settings.Save() 'by default saved on exit, other process needs to know now
        Me.Text &= ":" & My.Settings.pincrement.ToString

and for FormClosing event:
        Dim p = Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName)
        If p.Count = 1 Then My.Settings.pincrement = 0

Setting pincrement here is type Integer with scope User.
 
Back
Top