Hi,
I have a chat application which i have created using WinForms 2.0 (C#
lang).
The situation i am faced with is that i need to close all the opened
(chat, public chat, chat invite, chat history, user profile) windows
at the time of logout, except for the main window.
In my application, all the chat windows are opened on a separate
thread, and the user can then open the rest of the windows (chat
invite, chat history, user profile) from either the conversation
window thread or the main thread.
At the time of signout, i am using the following code to close all the
windows. But some how at times not all the windows get closed.
FormCollection formCollection = Application.OpenForms;
if (formCollection != null && formCollection.Count 0)
{
//skip i=0, as 0th form is the main form
for (int i = 1; i < formCollection.Count; i++)
{
Form form = formCollection[i];
if (form != null && form.IsDisposed != true)
{
if (form.InvokeRequired == false)
{
form.Close();
}
else
{
form.Invoke(new CloseFormDelegate(form.Close));
}
}
}
}
Any help in this regard will be highly appreciated.
Regards,
Ankit!!