Results 1 to 5 of 5

Thread: (Resolved) Problem with single instance application

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    (Resolved) Problem with single instance application

    I have a application set as a single instance and have set the event handler like this:
    vb Code:
    1. Namespace My
    2.     Partial Friend Class MyApplication
    3.         Private Sub MyApplication_StartupNextInstance( _
    4.             ByVal sender As Object, _
    5.             ByVal e As Microsoft.VisualBasic.ApplicationServices. _
    6.             StartupNextInstanceEventArgs) Handles Me.StartupNextInstance
    7.  
    8.             MessageBox.Show("Application is already open", _
    9.                 "Error Opening Form", MessageBoxButtons.OK)
    10.             e.BringToForeground = True
    11.  
    12.         End Sub
    13.     End Class
    14. End Namespace
    Everything seems to work ok as long is my applications isn't hidden (I hide the app to an icon in the system tray). When it is hidden the application is brought to the foreground but it doesn't show up on the screen and only shows as an application in the toolbar. Clicking on it doesn't do any thing to show it either. Is there something else I need to do to make this work correctly?
    Last edited by FastEddie; Aug 21st, 2007 at 10:59 PM.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: Problem with single instance application

    It sounds like your app is going from hidden to visible but minimized. If you click on the app in the toolbar, does it show up, or is it utterly unattainable?

    Also, when it comes back from being hidden, is it just sitting there, or is it running some code that would block paint messages from reaching the main window?
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    Re: Problem with single instance application

    I did get it to open once by right clicking it on the tool bar and maxmizing it but have not been able to do that again. It just gives me the move and close and size options (maximize is grayed out) when I right click on it.

    I did just disable all the code the runs when the form is maximized and got the same results so the only thing happening is the unhiding of the form:
    vb Code:
    1. #Region "Timer & Notifier"
    2.     Private Sub notCSA_BalloonTipClicked( _
    3.         ByVal sender As Object, _
    4.         ByVal e As System.EventArgs) Handles notCSA.BalloonTipClicked
    5.  
    6.         'btRefresh.PerformClick()
    7.  
    8.         Me.Visible = True
    9.         If Me.WindowState = FormWindowState.Minimized Then
    10.             Me.WindowState = FormWindowState.Normal
    11.         End If
    12.  
    13.         notCSA.Visible = False
    14.  
    15.     End Sub
    16.     Private Sub notCSA_MouseDown( _
    17.         ByVal sender As Object, _
    18.         ByVal e As System.Windows.Forms.MouseEventArgs) _
    19.         Handles notCSA.MouseDown
    20.  
    21.         If e.Button = Windows.Forms.MouseButtons.Left Then
    22.             Me.Visible = True
    23.             If Me.WindowState = FormWindowState.Minimized Then
    24.                 Me.WindowState = FormWindowState.Normal
    25.             End If
    26.  
    27.             notCSA.Visible = False
    28.  
    29.         End If
    30.     End Sub

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Problem with single instance application

    Try putting this in your StartupNextInstance event handler:
    vb.net Code:
    1. Me.MainForm.Show()
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    Re: Problem with single instance application

    Thanks . That seemed to do the trick.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width