473,770 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

App refuses to close

This message is in reply to a prev 1 .

My application refues to close . Some one had suggested that I might
have threads running.. but i solved that problem too . The app still
refuses to close . !!

Here is the code for one of them !!

I call a stop function to disconnect all objects (close ) . I also
make a call to Stop in the Dispose() function .
PLs Help
--------------------------------------------------------------------------------
using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
using System.Threadin g;
using System.Net;
using System.Net.Sock ets;
using System.IO;

namespace ServerT
{
/// <summary>
/// Summary description for Form1.
/// </summary>
///

public class Form1 : System.Windows. Forms.Form
{
private System.Windows. Forms.Button button1;
public String file2b=null;
private System.Windows. Forms.Button Exit;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;
private System.Windows. Forms.RichTextB ox rtb;
public int port = 6500;

public TcpListener serv,aux;

public int NoClients = 10;
public int ThisClient = 0;
private System.Windows. Forms.Label label1;
public System.Windows. Forms.ListBox listBox1;
public System.Boolean [] isFree;
public ServerT.connObj [] obj;
public Thread myThread;
public Thread startServ;
public Form2 fm;
private System.Windows. Forms.ListBox listBox2;
public System.Collecti ons.Queue myIPQ ;
public bool queueHasChanged =false;
private System.Windows. Forms.Button button2;
private System.Windows. Forms.Label label2;
private System.Windows. Forms.Button button3;
public Thread startServA;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();

//
// TODO: Add any constructor code after InitializeCompo nent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(Exit.Enabled )
this.Stop();
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
Application.Exi t();

}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.button1 = new System.Windows. Forms.Button();
this.Exit = new System.Windows. Forms.Button();
this.rtb = new System.Windows. Forms.RichTextB ox();
this.label1 = new System.Windows. Forms.Label();
this.listBox1 = new System.Windows. Forms.ListBox() ;
this.listBox2 = new System.Windows. Forms.ListBox() ;
this.button2 = new System.Windows. Forms.Button();
this.label2 = new System.Windows. Forms.Label();
this.button3 = new System.Windows. Forms.Button();
this.SuspendLay out();
//
// button1
//
this.button1.Lo cation = new System.Drawing. Point(296, 8);
this.button1.Na me = "button1";
this.button1.Si ze = new System.Drawing. Size(120, 32);
this.button1.Ta bIndex = 0;
this.button1.Te xt = "Start Server";
this.button1.Cl ick += new System.EventHan dler(this.butto n1_Click);
//
// Exit
//
this.Exit.Locat ion = new System.Drawing. Point(296, 88);
this.Exit.Name = "Exit";
this.Exit.Size = new System.Drawing. Size(120, 32);
this.Exit.TabIn dex = 1;
this.Exit.Text = "Stop";
this.Exit.Click += new System.EventHan dler(this.Exit_ Click);
//
// rtb
//
this.rtb.Locati on = new System.Drawing. Point(8, 8);
this.rtb.Name = "rtb";
this.rtb.Size = new System.Drawing. Size(224, 288);
this.rtb.TabInd ex = 2;
this.rtb.Text = "";
//
// label1
//
this.label1.Loc ation = new System.Drawing. Point(248, 8);
this.label1.Nam e = "label1";
this.label1.Siz e = new System.Drawing. Size(32, 32);
this.label1.Tab Index = 5;
//
// listBox1
//
this.listBox1.I temHeight = 20;
this.listBox1.L ocation = new System.Drawing. Point(424, 8);
this.listBox1.N ame = "listBox1";
this.listBox1.S ize = new System.Drawing. Size(160, 124);
this.listBox1.T abIndex = 6;
//
// listBox2
//
this.listBox2.I temHeight = 20;
this.listBox2.L ocation = new System.Drawing. Point(424, 144);
this.listBox2.N ame = "listBox2";
this.listBox2.S ize = new System.Drawing. Size(160, 144);
this.listBox2.T abIndex = 7;
//
// button2
//
this.button2.Lo cation = new System.Drawing. Point(296, 48);
this.button2.Na me = "button2";
this.button2.Si ze = new System.Drawing. Size(120, 32);
this.button2.Ta bIndex = 8;
this.button2.Te xt = "Start AServer";
this.button2.Cl ick += new System.EventHan dler(this.butto n2_Click);
//
// label2
//
this.label2.Loc ation = new System.Drawing. Point(248, 48);
this.label2.Nam e = "label2";
this.label2.Siz e = new System.Drawing. Size(32, 32);
this.label2.Tab Index = 10;
//
// button3
//
this.button3.Lo cation = new System.Drawing. Point(296, 128);
this.button3.Na me = "button3";
this.button3.Si ze = new System.Drawing. Size(120, 32);
this.button3.Ta bIndex = 11;
this.button3.Te xt = "Exit";
this.button3.Cl ick += new System.EventHan dler(this.butto n3_Click);
//
// Form1
//
this.AutoScaleB aseSize = new System.Drawing. Size(8, 19);
this.ClientSize = new System.Drawing. Size(592, 307);
this.Controls.A ddRange(new System.Windows. Forms.Control[] {
this.button3,
this.label2,
this.button2,
this.listBox2,
this.listBox1,
this.label1,
this.rtb,
this.Exit,
this.button1});
this.FormBorder Style =
System.Windows. Forms.FormBorde rStyle.FixedSin gle;
this.MaximizeBo x = false;
this.MinimizeBo x = false;
this.Name = "Form1";
this.Text = "Server Side";
this.Load += new System.EventHan dler(this.Form1 _Load);
this.ResumeLayo ut(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run (new Form1());

}

private void button1_Click(o bject sender, System.EventArg s e)
{

if(button1.Text .Equals("Start Server"))
{

startServ = new Thread(new ThreadStart(thi s.startListenin gC));

startServ.Name ="StartServe r";
startServ.Start ();
button1.Enabled = false;
Exit.Enabled = true;
}
}

public void startListeningC ()
{
try
{

label1.BackColo r = System.Drawing. Color.Green;
serv.Start();

while(true)
{
while(!serv.Pen ding())
{
Thread.Sleep(50 0);
if(label1.BackC olor == System.Drawing. Color.Red)
label1.BackColo r = System.Drawing. Color.Green;
else
label1.BackColo r = System.Drawing. Color.Red;

}
this.ThisClient =this.getClient No();

if(this.ThisCli ent!=-1)
{
obj[this.ThisClient] = new connObj();
obj[this.ThisClient].tc = serv.AcceptTcpC lient();
obj[this.ThisClient].No = this.ThisClient ;
isFree[this.ThisClient] = false;
listBox1.Items. Add("Client#"+t his.ThisClient. ToString());

obj[this.ThisClient].myForm = this;
this.myThread = new Thread(new
ThreadStart(obj[this.ThisClient].StartProtocol) );
obj[this.ThisClient].ConnType =
(int)Connection Type.ServerClie ntConnection;
obj[this.ThisClient].myThread = this.myThread;
this.myThread.S tart();

}
else
{
this.Text += "Clients Waiting...";
label1.BackColo r = System.Drawing. Color.Orange;
Thread.Sleep(50 00);
}

}

}
catch(Exception se)
{
MessageBox.Show ("Problem in Main Thread\n"+ se.Message +
"\nExecutio n Stopped");
this.Stop();
}
}

public void startListeningA ()
{
try
{

label2.BackColo r = System.Drawing. Color.Green;
aux.Start();

while(true)
{
while(!aux.Pend ing())
{
Thread.Sleep(50 0);
if(label2.BackC olor == System.Drawing. Color.Red)
label2.BackColo r = System.Drawing. Color.Green;
else
label2.BackColo r = System.Drawing. Color.Red;

}

this.ThisClient = this.getClientN o();
if(this.ThisCli ent!=-1)
{
obj[this.ThisClient] = new connObj();
obj[this.ThisClient].tc = aux.AcceptTcpCl ient();
obj[this.ThisClient].No = this.ThisClient ;
isFree[this.ThisClient] = false;
obj[this.ThisClient].myForm = this;
this.myThread = new Thread(new
ThreadStart(obj[this.ThisClient].StartProtocol) );
obj[this.ThisClient].ConnType =
(int)Connection Type.ServAuxCon nection;
obj[this.ThisClient].myThread = this.myThread;
this.myThread.S tart();

}
else
{
this.StdOut("Se rvers Waiting");
label2.BackColo r = System.Drawing. Color.Orange;
Thread.Sleep(50 00);
}

}

}
catch(Exception se)
{
MessageBox.Show ("Problem in Main Thread\n"+ se.Message +
"\nExecutio n Stopped");
this.Stop();
}
}

public int getClientNo()
{
for(int i=0;i<this.NoCl ients;i++)
{
if(isFree[i]==true)
return i;
}
return -1;
}

private void Exit_Click(obje ct sender, System.EventArg s e)
{
this.Stop();
button1.Enabled = true;
button2.Enabled = true;
Exit.Enabled = false;

}

void Stop()
{
Exit.Enabled = false;
label1.BackColo r = System.Drawing. Color.Red;
label2.BackColo r = System.Drawing. Color.Red;
if(startServ!=n ull)
{
if(startServ.Is Alive)
{
startServ.Suspe nd();
serv.Stop();
}
}

if(startServA!= null)
{
if(startServA.I sAlive)
{
this.startServA .Suspend();
aux.Stop();
}
}
if(this.getClie ntNo()!=0)
{
for(int i=0;i<this.NoCl ients;i++)
{
if(!isFree[i])
{
obj[i].disconnect();

}
}
}
}

private void Form1_Load(obje ct sender, System.EventArg s e)
{

this.Text = System.Net.Dns. GetHostName() + " Central Server";
label1.BackColo r = System.Drawing. Color.Red;
label2.BackColo r = System.Drawing. Color.Red;
isFree = new System.Boolean[this.NoClients];
for(int i=0;i<this.NoCl ients;i++)
{
isFree[i] = true;

}
obj = new connObj[this.NoClients];
this.myIPQ = new System.Collecti ons.Queue();
Exit.Enabled = false;
try
{
serv = new TcpListener(por t);//Client Port
aux = new TcpListener(700 0);//Aux port
}
catch(Exception se)
{
MessageBox.Show (se.Message);
}
}

public void StdOut(String s)
{
rtb.Text += "\n" + s;
}

private void button2_Click(o bject sender, System.EventArg s e)
{
startServA = new Thread(new ThreadStart(thi s.startListenin gA));

startServA.Name ="StartServerA" ;
startServA.Star t();
button2.Enabled = false;
Thread painter = new Thread(new ThreadStart(thi s.paintQ));
painter.Start() ;
Exit.Enabled = true;
}

private void paintQ()
{
while(true)
{
Thread.Sleep(50 0);

System.Collecti ons.IEnumerator iter = this.myIPQ.GetE numerator();
this.listBox2.I tems.Clear();
while(iter.Move Next())
{
listBox2.Items. Add(iter.Curren t.ToString());
}
}
}

private void button3_Click(o bject sender, System.EventArg s e)
{
this.Dispose();

}


}

}
Nov 15 '05 #1
1 1843
I did not read your code, but I guess you need something like:

System.Environm ent.Exit( 0 );

on your way out.
Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1315
by: Wayne Aprato | last post by:
Can anyone please help me with the following madness in Access 2003 (2000 file format). I am using 2 similar funtions, the first which works fine to save reports as snapshots: On Error Resume Next DoCmd.OutputTo A_REPORT, Forms!FrontPage!RptName, "Snapshot Format (*.snp)", , False and the second which is giving me the problem, to email reports as snapshots:
7
2015
by: Daniel | last post by:
I have an winform application that uses System.IO.StreamReader and Serializer.Deserialize to load some data from a file, if any error is detected in the file a new file should be written to the same directory, I use a StreamWriter and Serializer.Serialize to do this. The problem is that when the streamreader has opened the file it does not release it until the application is closed. When I try to use the StreamWriter to write the new...
1
2008
by: ticmanis | last post by:
Hello, I'm having trouble getting MSIE 6.0 (running on XP SP2) to accept a cookie which works fine in both Firefox and wget. The web server is Boa 0.94.13 (a small embedded server) using PHP 4.3.10 for CGI. Even with the lowest security settings in MSIE there is no cookie acceptance, and no "Cookie:" HTTP header is being sent back by MSIE. This is the php code for a fairly minimal testcase:
13
6213
by: teric2 | last post by:
Hi Everyone! I have a form that opens from a another form set as a dialog box via a command button. I have tried about everything I can think of to make this form maximize when it opens. I've used the dcmd.maximize in the "on open" and "on load" event procedures of the form. Also tried using it in the code of the command button that opens the form. Nothing seems to force this pesky thing to maximize. What am I doing wrong? Here's the...
3
1157
by: RadhikaG | last post by:
my dropdownlist_selectedindexchange method just refuses to get invoked when i switch from any value in the dropdown list to the default value. why??? how do i get it work for this as well?
12
4258
by: Rainer Queck | last post by:
Hi NG, I have no idea why, but since a while a dataset refuses to write to a specific xml file. I get the error message "Der Zugriff auf den Pfad D:\VS2005Projects\BfpNet\BfpNet\bin\Debug\Bfp.xml wurde verweigert" which translates to: "The access to the path D:\VS...... was denied". The dataset can read from this Bfp.xml without any problems.
0
1071
by: poe | last post by:
Hello, I have a large database table running on SQL Server 8.0. It currently has nearly 98 million records on it's ways to 125 million. I am doing inserts as quickly as the server can handle it, but after a while the server simply refuses to process the insert statements. According to SQL Management Studio, the insert statements are being loaded and marked as runnable, but they are never added to the database. SQL Server doesn't stop...
0
1533
by: VaBa | last post by:
Hi, Need some help.. I have a VBA class module in MS ACCESS. In the same MS ACCESS app, I am calling a .NET DLL (which i have exposed as COM-visible) and passing BYREF an instance of the VBA class module as an argument to one of the .NET DLL method. Step by step, here's what i am doing: 1. Create vba class module in MS ACCESS Option Compare Database Option Explicit ... Public Function DoSomething(ByVal S as String, ByRef RetVal as...
5
1741
by: NDayave | last post by:
How Do, I have a rather simple website, which has some SQL embedded in the ASP to write user data to the underlying mdb database. The first SQL statement looks up all the records in the database to help produce the required output which is a single string value which is the Customer's Order to be made in store for pickup. The second is to write the string into the database, and keeps shouting about a syntax error in the INSERT INTO...
0
9617
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9453
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10254
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10099
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10036
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.