Thread abort Problem

  • Thread starter Thread starter chi.chung.ko
  • Start date Start date
C

chi.chung.ko

Dear all:

In .NET Compact Framework Form I start one thread
the thread is always listen use TcpListener method
When Form will be closed must be Stop TcpListener
but How Can I abort thread first?
because if thread isn't abort will be error when TcpListener stop

Tks for helpï¼
 
I think that's what you want. Set a flag for the thread to see and close
the listener. An error will be generated, the thread will catch it, check
the flag, see that it's time to exit, and ignore the error.

Paul T.

Dear all:

In .NET Compact Framework Form I start one thread
the thread is always listen use TcpListener method
When Form will be closed must be Stop TcpListener
but How Can I abort thread first?
because if thread isn't abort will be error when TcpListener stop

Tks for help!
 
Thanks for your help
I have already set flag default is false.
when form closed,In Form_closing set flag is true.
In Thread judge if flag is true than break.
Run In Emu is Ok.
But In real device will show NullReferenceException,
Application::Run+0x1a,FormName::Main+0xa
How can I solve the Error?
Thanks!
 
We do not have enough information to answer...

Paul T.

Thanks for your help
I have already set flag default is false.
when form closed,In Form_closing set flag is true.
In Thread judge if flag is true than break.
Run In Emu is Ok.
But In real device will show NullReferenceException,
Application::Run+0x1a,FormName::Main+0xa
How can I solve the Error?
Thanks!
 
form_closing set flag true.
In thread judge the flag is true
it still generate error.
my solve method is catch the socketexception and break
Run in Emu is Ok
 
part of my source code
System.Threading.ThreadStart startListen = new ThreadStart(listen);
thd = new Thread(startListen);
thd.Start();
-------------------------------
listen()
{
System.Net.IPAddress
CEAddr = System.Net.Dns.Resolve(dns).AddressList[0];
server = new TcpListener(CEAddr,port);
server.Start();
Byte[] bytes = new Byte[256];

while(true)
{
//Console.WriteLine("Waiting for a connection...");
client = server.AcceptTcpClient();

...............................
}
}

-----------------------
in form_closing set server.stop will led "client =
server.AcceptTcpClient();" generate error

if set flag and ignore the error Run In Emu will be ok

but in Real device will be generate another error
Thanks
 
Sorry, I still don't understand. Create a complete application that
simulates what you're seeing, indicate what state the socket is in when
you're exiting the application and I'll try to make some time to test it.

Paul T.
 
Back
Top