PC Review


Reply
Thread Tools Rate Thread

Can't exit app after BeginReceive

 
 
Mike
Guest
Posts: n/a
 
      9th May 2005
I've seen a bit of traffic in this group about similar problems but am
not quite sure if this is the same. I have an app that needs to read
asynchronous data over a socket forever, handling it as it comes in.
The app needs to continue to perform other tasks based on user input.

So, I create a socket, connect it to my serving app (running on the
same device) and call BeginRecieve. All is working as expected except
that when I call Application.Exit(), the application does not exit.
I've tried calling Shutdown() on the socket, but this did not help.

Thanks,
Mike

 
Reply With Quote
 
 
 
 
Paul G. Tobey [eMVP]
Guest
Posts: n/a
 
      9th May 2005
There's a thread being started by that call and the thread isn't exiting. I
don't know what would break it out there, but I'd try calling socket.Close()
before anything else. For better control over what's going on, use your own
thread with blocking calls rather than BeginXXX(), which creates the thread
behind your back.

Paul T.


"Mike" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I've seen a bit of traffic in this group about similar problems but am
> not quite sure if this is the same. I have an app that needs to read
> asynchronous data over a socket forever, handling it as it comes in.
> The app needs to continue to perform other tasks based on user input.
>
> So, I create a socket, connect it to my serving app (running on the
> same device) and call BeginRecieve. All is working as expected except
> that when I call Application.Exit(), the application does not exit.
> I've tried calling Shutdown() on the socket, but this did not help.
>
> Thanks,
> Mike
>



 
Reply With Quote
 
Robert Jordan
Guest
Posts: n/a
 
      9th May 2005
Mike wrote:

> I've seen a bit of traffic in this group about similar problems but am
> not quite sure if this is the same. I have an app that needs to read
> asynchronous data over a socket forever, handling it as it comes in.
> The app needs to continue to perform other tasks based on user input.
>
> So, I create a socket, connect it to my serving app (running on the
> same device) and call BeginRecieve. All is working as expected except
> that when I call Application.Exit(), the application does not exit.
> I've tried calling Shutdown() on the socket, but this did not help.


You may try ExitProcess:

[System.Runtime.InteropServices.DllImport("coredll.dll")]
public static extern void ExitProcess(uint uExitCode);

Rob
 
Reply With Quote
 
Paul G. Tobey [eMVP]
Guest
Posts: n/a
 
      9th May 2005
I don't think that you want to do that, even if it works. When you have a
problem that is caused by you leaving some resources, a thread in this case,
allocated, the right fix is to deallocate them, not to find a bigger hammer
to exit the process with.

Paul T.

"Robert Jordan" <(E-Mail Removed)> wrote in message
news:d5opa2$ab0$01$(E-Mail Removed)...
> Mike wrote:
>
>> I've seen a bit of traffic in this group about similar problems but am
>> not quite sure if this is the same. I have an app that needs to read
>> asynchronous data over a socket forever, handling it as it comes in.
>> The app needs to continue to perform other tasks based on user input.
>>
>> So, I create a socket, connect it to my serving app (running on the
>> same device) and call BeginRecieve. All is working as expected except
>> that when I call Application.Exit(), the application does not exit.
>> I've tried calling Shutdown() on the socket, but this did not help.

>
> You may try ExitProcess:
>
> [System.Runtime.InteropServices.DllImport("coredll.dll")]
> public static extern void ExitProcess(uint uExitCode);
>
> Rob



 
Reply With Quote
 
Mike
Guest
Posts: n/a
 
      10th May 2005
I've tried calling Close after calling Shutdown, as the documentation
says to do, but then I get a System.ObjectDisposedException. I'll give
the direct threading method a try.

 
Reply With Quote
 
Paul G. Tobey [eMVP]
Guest
Posts: n/a
 
      10th May 2005
Try calling Close() and forgetting about Shutdown().

Paul T.

"Mike" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I've tried calling Close after calling Shutdown, as the documentation
> says to do, but then I get a System.ObjectDisposedException. I'll give
> the direct threading method a try.
>



 
Reply With Quote
 
Mike
Guest
Posts: n/a
 
      10th May 2005
I had tried all cominations of Shutdown, Close, and EndReceive that I
could think of. I hate to say it (or love to say it) but...

I switched back to my PC from the laptop I was working on, and now
everything is fine (without calling Close, Shutdown, or anything). So
I'll have to chalk this up to user error or a bad insall on my laptop
(using VS2005 beta 2 in both cases).

Thanks for the help.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
socket beginreceive and thread exit William Stacey [C# MVP] Microsoft Dot NET Framework 2 8th Dec 2006 05:48 AM
BeginReceive not ASYNC. Bob Microsoft Dot NET Framework 1 13th Jan 2006 06:00 PM
BeginReceive Callback Preempted AndyGeers Microsoft C# .NET 0 14th May 2004 10:59 AM
Socket.BeginReceive Question Mike Hildner Microsoft Dot NET Framework 2 10th Oct 2003 03:30 PM
Socket.BeginReceive() TP-Software Microsoft Dot NET 3 11th Sep 2003 11:10 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:26 AM.