Solved

how to close windows form in vb.net

Posted on 2014-11-04
7
427 Views
Last Modified: 2014-12-29
Hi

i have the following simple code in my windows form application (vb.net + VS2010)
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
         
         

        SendNotification()
 
        Application.DoEvents()
        Application.Exit()
    End Sub

Open in new window


my problem is while the program is executing the function SendNotification() the program will jump to Application.DoEvents() and         Application.Exit() causing the form to be closed while some events are not completed in the function SendNotification()

any suggestion pls?
0
Comment
Question by:Kamal Khaleefa
7 Comments
 
LVL 6

Expert Comment

by:Mandeep Singh
ID: 40423303
Use

FormName.Close()

or

Me.close()
0
 
LVL 16

Author Comment

by:Kamal Khaleefa
ID: 40423332
yes thats correct but my problem as described up i need to close the form after all events are executed successfully
0
 
LVL 11

Expert Comment

by:louisfr
ID: 40423372
It depends on what the SendNotification method does.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 250 total points
ID: 40423451
SendNotification is probably an asynchrone method. The code continues without waiting when you call an asynchrone method.

Look at the documentation for the function. There could be a way to call it so that it runs synchronously. There might be an event that you can subscribe to that will trigger when the method has finished. There could be an alternative method that you can call instead, such as the ShowDialog (synchrone) that can be used instead of the Show method (asynchrone) to display a Windows Form.
0
 
LVL 16

Author Comment

by:Kamal Khaleefa
ID: 40423600
@Jacques Bourgeois (James Burger)

you are absolutely correct . this is asynchronous  method used to send push notification for apple /iPhone

 Sub SendNotification()

        Dim push As New PushBroker


        AddHandler push.OnNotificationSent, AddressOf NotificationSent
        AddHandler push.OnChannelException, AddressOf ChannelException
        AddHandler push.OnServiceException, AddressOf ServiceException
        AddHandler push.OnNotificationFailed, AddressOf NotificationFailed
        AddHandler push.OnDeviceSubscriptionExpired, AddressOf DeviceSubscriptionExpired
        AddHandler push.OnDeviceSubscriptionChanged, AddressOf DeviceSubscriptionChanged
        AddHandler push.OnChannelCreated, AddressOf ChannelCreated
        AddHandler push.OnChannelDestroyed, AddressOf ChannelDestroyed

'some code is done here
end sub

Open in new window


is there a way to close the form and kill the process after i make sure all the code is executed
0
 
LVL 33

Assisted Solution

by:it_saige
it_saige earned 250 total points
ID: 40424147
You need to decide which event(s) signify that your process has completed.  NotificationSent, NotificationFailed and ChannelDestroyed look like good candidates.  So long as you are not sending multiple notifications, then you could easily tell the program to exit when you receive any of those events.

If you are sending multiple notifications, then you need to use some sort of Queue or List to send from, what you could do is also wait until the list is exhausted and signal to close your application using the above events and a boolean value indicating that it is ok to close.

If you are using a Queue, then you will need to specify a boolean value that states whether you are adding additional items to the Queue.  Once this boolean value is false and the queue is exhausted, then you can signal to close your application using the above events and a boolean value indicating that it is ok to close.

-saige-
0
 
LVL 16

Author Closing Comment

by:Kamal Khaleefa
ID: 40521584
Thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question