473,387 Members | 3,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Threads - ask for advice

Hi.
I have written client and server app. that sends files.
Client application doesn't use threads, but server does.
I would like to show you part of my code ( thread) and ask why, when i
close program, it's still visible in processes.
I have also created bool variable "closing", by which thread recognize
if program is quit ( set "closing = true" in dispose method )
private void thd()
{
TcpListener Server = new TcpListener(5000);

try
{
Server.Start();
}
catch (SocketException ex)
{
if (MessageBox.Show(ex.Message, "tcpListener.Start()
error",
MessageBoxButtons.OK, MessageBoxIcon.Error) ==
DialogResult.OK) this.Dispose();
}

while (!closing && Server!=null)
{
Socket connection = Server.AcceptSocket();

if (connection!= null && connection.Connected)
{
String fName = rFileName(connection);
storeFile(connection, fName);
}
GC.Collect();
}
}

Dec 1 '05 #1
2 1030
Piotrekk wrote:
Hi.
I have written client and server app. that sends files.
Client application doesn't use threads, but server does.
I would like to show you part of my code ( thread) and ask why, when i
close program, it's still visible in processes.
I have also created bool variable "closing", by which thread recognize
if program is quit ( set "closing = true" in dispose method )
Just a guess... the server thread is still blocked in
Server.AcceptSocket(), so setting "closing" to true doesn't help much
because it won't event see it. You can verify this with the debugger,
click break and open the threads window.

I'd try doing this with async sockets or using Socket.Poll to wait for
connections.
GC.Collect();


Thats normally unnecessary..

hth,
Max
Dec 1 '05 #2
Hi,

Run this method from a thread marked with IsBackground = true
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Piotrekk" <Pi*************@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hi.
I have written client and server app. that sends files.
Client application doesn't use threads, but server does.
I would like to show you part of my code ( thread) and ask why, when i
close program, it's still visible in processes.
I have also created bool variable "closing", by which thread recognize
if program is quit ( set "closing = true" in dispose method )
private void thd()
{
TcpListener Server = new TcpListener(5000);

try
{
Server.Start();
}
catch (SocketException ex)
{
if (MessageBox.Show(ex.Message, "tcpListener.Start()
error",
MessageBoxButtons.OK, MessageBoxIcon.Error) ==
DialogResult.OK) this.Dispose();
}

while (!closing && Server!=null)
{
Socket connection = Server.AcceptSocket();

if (connection!= null && connection.Connected)
{
String fName = rFileName(connection);
storeFile(connection, fName);
}
GC.Collect();
}
}

Dec 1 '05 #3

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

Similar topics

0
by: Mark Stokes | last post by:
Hi there, I wanted a bit of advice on a program (a prototype) that I am trying to write that uses threads. I will outline what I am attempting to do, and if anyone has any advice on the way I...
4
by: Senthil | last post by:
Hi.. Can anyone tell how to find the threads(name or ID) running in the background using C#. I want to find those threads and to terminate if needed. Thanks, Palani.
1
by: RahimAsif | last post by:
Hi guys, I would like some advice on thread programming using C# so I wanted some advice. I am writing an application that communicates with a panel over ethernet, collects data and writes it...
6
by: RahimAsif | last post by:
Hi guys, I would like some advice on thread programming using C#. I am writing an application that communicates with a panel over ethernet, collects data and writes it to a file. The way the...
3
by: Anders Both | last post by:
Does someone know´s about using threads and/or asynchronous programming inside asp.net (inside the asp.net process). I am here not speaking about the thing that the IIS makes new threads for each...
6
by: Gary Lee | last post by:
In VB.NET using CDO, I'd like to allow multiple threads to share a single MAPI.Session object. If I declare and instantiate sessions within each thread, I'm OK (although this negates the...
10
by: Brad | last post by:
I need to learn about threads and threading. I currently have a process that is pulling 10 to 12 thousand records from the AS400 and formatting the data then storing into a SQL server. This...
2
by: Matthew Tylee Atkinson | last post by:
I appear to be having some problems with the isAlive() method of detecting if a thread is alive/active/running or not. I'd be grateful for any advice. I have a visualisation program (which uses...
4
by: tdahsu | last post by:
All, I'd appreciate any help. I've got a list of files in a directory, and I'd like to iterate through that list and process each one. Rather than do that serially, I was thinking I should...
167
by: darren | last post by:
Hi I have to write a multi-threaded program. I decided to take an OO approach to it. I had the idea to wrap up all of the thread functions in a mix-in class called Threadable. Then when an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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...

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.