Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Close all threads when application closes
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  14 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
KC Eric  
View profile  
 More options Mar 29 2005, 9:51 am
Newsgroups: microsoft.public.dotnet.framework.compactframework
From: "KC Eric" <kceric@nospam>
Date: Tue, 29 Mar 2005 22:51:10 +0800
Local: Tues, Mar 29 2005 9:51 am
Subject: Close all threads when application closes
Hi all,

I have some threads,
one is UI thread,
one is worker thread, which uses sockets to wait for incoming messages.

I deploy it in emulator, then I click OK in the top right corner,
but then I can't deploy again, unless I closed the emulator, the error is
something like it can't output to that file.
I suspect that not all the threads were closed, and I suspect the sockets
were still waiting.
In PC, I can set thread.isBackground = true to solve this problem,
but in PPC, .net CF doesn't support thread.isBackground,
so how to solve this problem?

Thanks much!

KC Eric

--
-> 鼓足幹勁,力爭上游,多快好省地建設理想FYP主義
-> 堅決遵從鵬哥四項表述,全面落實大鵬金總路線,走向四個物件初始化
-> 爹親娘親都不及金鵬哥親 XDDD
-> To be energetic to strive for the best. To build our FYP idealism in a
flourishing, rapid, perfect and efficient manner.
-> To firmly adhere to Pango's Four Statements. To comprehensively implement
The Giant Pango's Great Scheme. To stride forward to the Initialization of
The Four Objects.
-> Parents are not as close as Pango. XDDD


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sergey Bogdanov  
View profile  
 More options Mar 29 2005, 10:15 am
Newsgroups: microsoft.public.dotnet.framework.compactframework
From: Sergey Bogdanov <sergey.bogda...@gmail.com>
Date: Tue, 29 Mar 2005 18:15:34 +0300
Local: Tues, Mar 29 2005 10:15 am
Subject: Re: Close all threads when application closes
You should implement your worker thread in this manner:

WorkerThread
{
        while(isRunning)
        {
                ...
        }

}

when you set isRunning flag to true thread should accurately complete
its job. You have said that you are using Socket (I suppose blocked).
Then before exit close also socket - socket.Receive will throw an
SocketException (you should also capture it in a worker thread;
otherwise a Thread will be hanging) and after that wait till your thread
complete job. Here you are pseudo code:

1. spawn a worker thread using OpenNETCF's ThreadEx instead of Thread
(you will be needed in .Join method later)
2. set flag isRunning = false in OnClose event handler
3. WorkerThreadSocket.Close()
4. WorkerThread.Join(10000)

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ginny Caughey [MVP]  
View profile  
 More options Mar 29 2005, 11:17 am
Newsgroups: microsoft.public.dotnet.framework.compactframework
From: "Ginny Caughey [MVP]" <ginny.caughey.onl...@wasteworks.com>
Date: Tue, 29 Mar 2005 11:17:48 -0500
Local: Tues, Mar 29 2005 11:17 am
Subject: Re: Close all threads when application closes
KC

In addition to Sergey's great reply, in the next version of the Compact
Framework background threads should work as you expect.

--
Ginny Caughey
.Net Compact Framework MVP

"KC Eric" <kceric@nospam> wrote in message

news:O30A86GNFHA.1948@TK2MSFTNGP14.phx.gbl...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
KC Eric  
View profile  
 More options Mar 29 2005, 11:34 am
Newsgroups: microsoft.public.dotnet.framework.compactframework
From: "KC Eric" <kceric@nospam>
Date: Wed, 30 Mar 2005 00:34:52 +0800
Local: Tues, Mar 29 2005 11:34 am
Subject: Re: Close all threads when application closes
Thanks!

I am using non-blocking socket, I use BeginReceive(), so is it the same
logic and any changes to the Pseudo code?

Thanks much!

KC Eric

"Sergey Bogdanov" <sergey.bogda...@gmail.com> ???
news:eiw7oIHNFHA.2372@TK2MSFTNGP10.phx.gbl ???...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sergey Bogdanov  
View profile  
 More options Mar 29 2005, 1:03 pm
Newsgroups: microsoft.public.dotnet.framework.compactframework
From: Sergey Bogdanov <sergey.bogda...@gmail.com>
Date: Tue, 29 Mar 2005 21:03:01 +0300
Local: Tues, Mar 29 2005 1:03 pm
Subject: Re: Close all threads when application closes
Yes, the same technique applies to non-blocking sockets. A
SocketException will be thrown by the EndReceive when you close you socket.

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brian Smith [MSFT]  
View profile  
 More options Mar 29 2005, 8:28 pm
Newsgroups: microsoft.public.dotnet.framework.compactframework
From: briansm@nospam_microsoft.com (Brian Smith [MSFT])
Date: Wed, 30 Mar 2005 01:28:53 GMT
Local: Tues, Mar 29 2005 8:28 pm
Subject: Re: Close all threads when application closes
I should give a warning about background threads in .netcf v2 (Whidbey) --
they might not work entirely "as you expect". If a background thread is
blocked down in native code (in a pinvoke), the execution engine will not
be able to force it out to allow the process to terminate. Regrettably,
this includes threads that are in networking calls. Even non-blocking
socket calls will often cause an internal worker thread within .netcf to
end up blocked in a way that we cannot wake up. So even in v2, you will
need to play tricks like the ones discussed in this thead to allow your
application to exit cleanly.

Background threads will work "as you expect" if they are running within
managed code or blocked on a managed synchonization object (Event, Mutex,
Monitor, Sleep).

I'm not sure if this limitation has been spelled out before. It is one that
we know might be a problem but we were unable to get a good solution worked
out for this coming release.

Brian

--------------------

This posting is provided "AS IS" with no warranties, and confers no rights.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ginny Caughey [MVP]  
View profile  
 More options Mar 29 2005, 8:42 pm
Newsgroups: microsoft.public.dotnet.framework.compactframework
From: "Ginny Caughey [MVP]" <ginny.caughey.onl...@wasteworks.com>
Date: Tue, 29 Mar 2005 20:42:01 -0500
Local: Tues, Mar 29 2005 8:42 pm
Subject: Re: Close all threads when application closes
Thanks, Brian. I wasn't aware of that limitation. That's a good warning!

--
Ginny Caughey
.Net Compact Framework MVP

"Brian Smith [MSFT]" <briansm@nospam_microsoft.com> wrote in message
news:J0IbYfMNFHA.3320@TK2MSFTNGXA03.phx.gbl...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dick Grier  
View profile  
 More options Mar 30 2005, 11:07 am
Newsgroups: microsoft.public.dotnet.framework.compactframework
From: "Dick Grier" <dick_grierNOS...@msn.com>
Date: Wed, 30 Mar 2005 09:07:43 -0700
Local: Wed, Mar 30 2005 11:07 am
Subject: Re: Close all threads when application closes
Hi Ginny,

This is why I implement my own background thread for Socket reads.  It does
NOT use BeginReceive, so doesn't experience this problem.  Naturally, the
application still needs to notify the thread to exit prior to termination.

Anyone who wants a simple example that illustrates this (VB .NET, naturally)
can send me email at dick_gr...@msn.com.

Dick

--
Richard Grier  (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2  (391 pages) published July 2004.  See
www.mabry.com/vbpgser4 to order.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ginny Caughey [MVP]  
View profile  
 More options Mar 30 2005, 1:10 pm
Newsgroups: microsoft.public.dotnet.framework.compactframework
From: "Ginny Caughey [MVP]" <ginny.caughey.onl...@wasteworks.com>
Date: Wed, 30 Mar 2005 13:10:50 -0500
Local: Wed, Mar 30 2005 1:10 pm
Subject: Re: Close all threads when application closes
Dick,

That certainly sounds like a good strategy. Asynchronous calls just don't
look so attractive when there's no way to abort them.

--
Ginny Caughey
.Net Compact Framework MVP

"Dick Grier" <dick_grierNOS...@msn.com> wrote in message

news:%23QrpaKUNFHA.1268@TK2MSFTNGP14.phx.gbl...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Moth  
View profile  
 More options Mar 30 2005, 1:54 pm
Newsgroups: microsoft.public.dotnet.framework.compactframework
From: "Daniel Moth" <dmot...@hotmail.com>
Date: Wed, 30 Mar 2005 19:54:29 +0100
Local: Wed, Mar 30 2005 1:54 pm
Subject: Re: Close all threads when application closes
Brian this info is not spelled out anywhere else, thanks.

> Background threads will work "as you expect" if they are running within
> managed code or blocked on a managed synchonization object (Event, Mutex,
> Monitor, Sleep).

You say "managed synchronization object". So if I have pinvoked and
WaitForSingleObject myself, will that thread not be woken up and shut down
when the app terminates?

Cheers
Daniel
--
http://www.danielmoth.com/Blog/

"Brian Smith [MSFT]" <briansm@nospam_microsoft.com> wrote in message
news:J0IbYfMNFHA.3320@TK2MSFTNGXA03.phx.gbl...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brian Smith [MSFT]  
View profile  
 More options Mar 30 2005, 3:01 pm
Newsgroups: microsoft.public.dotnet.framework.compactframework
From: briansm@nospam_microsoft.com (Brian Smith [MSFT])
Date: Wed, 30 Mar 2005 20:01:29 GMT
Local: Wed, Mar 30 2005 3:01 pm
Subject: Re: Close all threads when application closes
Daniel, you are correct: a background thread blocked on a
WaitForSingleObject within a pinvoke will NOT be automatically woken up to
allow the application to shut down. Only fully managed objects created and
waited-on through the System.Threading classes are controllable by .netcf.
This is because the .netcf execution engine itself is just like any other
application running on Windows CE and has no special access to internal OS
data structures or "backdoor" APIs. It doesn't know what a thread inside a
pinvoke is doing or what it might be blocked on. The only mechanism
available to terminate it would be the Windows TerminateThread API. Killing
a thread in this way without any way for it to clean itself up could leave
the process or the larger system in a bad state if the thread was using or
modifying shared resources (mutexes, files, etc). The dangers are
especially great when more than one AppDomain is running within a single
process.

Only the application itself knows when and how to safely exit such a thread
and .netcf will rely on the application to do so. In future releases, we
will try to fix some of the situations (such as the managed sockets case)
in which .netcf has enough knowledge to clean up safely and automatically.
But the general pinvoke case will probably remain as it is for the
foreseeable future unless the current non-solution causes more problems
that it solves. Hopefully in the future, the managed development
environment will be rich enough that pinvokes will be less necessary and
the problem will disappear.

Brian
--------------------

This posting is provided "AS IS" with no warranties, and confers no rights.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Moth  
View profile  
 More options Mar 30 2005, 4:47 pm
Newsgroups: microsoft.public.dotnet.framework.compactframework
From: "Daniel Moth" <dmot...@hotmail.com>
Date: Wed, 30 Mar 2005 22:47:01 +0100
Local: Wed, Mar 30 2005 4:47 pm
Subject: Re: Close all threads when application closes
Brian, thank you again for the useful info.

In my opinion, the CF team should make these facts very public and at least
make sure there is a CF-specific annotation to the IsBackground property in
the documentation.

Cheers
Daniel
--
http://www.danielmoth.com/Blog/

"Brian Smith [MSFT]" <briansm@nospam_microsoft.com> wrote in message
news:bNm%23GNWNFHA.1796@TK2MSFTNGXA03.phx.gbl...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ginny Caughey [MVP]  
View profile  
 More options Mar 30 2005, 5:40 pm
Newsgroups: microsoft.public.dotnet.framework.compactframework
From: "Ginny Caughey [MVP]" <ginny.caughey.onl...@wasteworks.com>
Date: Wed, 30 Mar 2005 17:40:45 -0500
Local: Wed, Mar 30 2005 5:40 pm
Subject: Re: Close all threads when application closes
Daniel,

Good point about a warning in the docs. This behavior is not what people
will expect.

--
Ginny Caughey
.Net Compact Framework MVP

"Daniel Moth" <dmot...@hotmail.com> wrote in message

news:%23KZplHXNFHA.2604@TK2MSFTNGP10.phx.gbl...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brian Smith [MSFT]  
View profile  
 More options Mar 31 2005, 9:03 pm
Newsgroups: microsoft.public.dotnet.framework.compactframework
From: briansm@nospam_microsoft.com (Brian Smith [MSFT])
Date: Fri, 01 Apr 2005 02:03:45 GMT
Local: Thurs, Mar 31 2005 9:03 pm
Subject: Re: Close all threads when application closes
It's public now for anyone to Google -- I mean MSN Search :-)
But you raise a good point. I'll pass the information along to our
documentation folks. I'm not sure where the information will best fit but
it should go somewhere.

--------------------

This posting is provided "AS IS" with no warranties, and confers no rights.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google