Solved

how to close windows form in vb.net

Posted on 2014-11-04
7
424 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb.net checkbox 7 41
Two different visual studio versions 3 23
Need a starter for ETL protocol? 4 42
Get the selected ValueMember of Combobox 5 21
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now