Threading with PInvoke Freezes Application

R

Rick Winscot

Threading with PInvoke Freezes Application

I am working on some apps with threading. In this particular app - the
device becomes unresponsive (highly duplicatable) when calling an audio
function through PInvoke... I get similar results while calling anything
with
PInvoke and using threads.

Has anyone else experienced this kind of activity with threading? It would
be ever so helpful if the thread priority (.NET CF) was supported. Hint
Hint.

Cheers,

Rick Winscot
rickly@zyche dot com
 
D

Daniel Moth

I think Thread.Priority is supported... 249-253 at least... Have you tried
it?

Cheers
Daniel
 
E

Erik J Rubin [MS]

Many of the Audio functions you can call through PInvoke (eg, PlaySound)
will block the calling thread while the sound is playing. If you are
calling them in your main thread then it could easily make your app stop
responding until the PInvoke occurs.

The PlaySound API call actually has a flag to indicate whether it
operates in synchronous or async mode.

Also, as for threading in general, are you trying to update form controls
from a thread that doesn't own the form? That will cause application
instability on the .NET CF. There is a workaround for this called
"ControlInvoker" which if you dig around on the MS support site, you can
find. This lets you invoke methods on forms from threads that do not own
the form.

Hope that helps

-- Erik
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "Rick Winscot" <[email protected]>
| Subject: Threading with PInvoke Freezes Application
| Date: Mon, 18 Aug 2003 16:41:54 -0600
| Lines: 18
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| NNTP-Posting-Host: 205.127.17.136
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:31237
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| Threading with PInvoke Freezes Application
|
| I am working on some apps with threading. In this particular app - the
| device becomes unresponsive (highly duplicatable) when calling an audio
| function through PInvoke... I get similar results while calling anything
| with
| PInvoke and using threads.
|
| Has anyone else experienced this kind of activity with threading? It
would
| be ever so helpful if the thread priority (.NET CF) was supported. Hint
| Hint.
|
| Cheers,
|
| Rick Winscot
| rickly@zyche dot com
|
|
|
 
E

Erik J Rubin [MS]

Hmmmm.... I am afraid I don't know what could be the problem exactly.

Some of the common issues are the usual suspects: stack overflow, buffer
overrun. Are you receiving a buffer from the API call, or are you passing
memory to the P/Invoke?

I admit, I am grasping at straws at this point. Maybe if you posted some
code there would be someone here who would know somthing.

Thanks


This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "Rick Winscot" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: Re: Threading with PInvoke Freezes Application
| Date: Tue, 19 Aug 2003 18:45:15 -0600
| Lines: 77
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| NNTP-Posting-Host: 12-209-181-25.client.attbi.com 12.209.181.25
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:31399
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| Erik,
|
| Thanks for the ideas... but... The PInvoke call is to a midi dll - and
does
| not reference the PlaySound api. I am not updating anything from the
| thread - its sole purpose is to call the midi player in a thread... so the
| app can continue to respond to mouse clicks.
|
| From the debugger - it appears that the application freezes just before
the
| thread exits.
|
| Rick Winscot
| rickly@zyche dot com
|
|
| | > Many of the Audio functions you can call through PInvoke (eg,
PlaySound)
| > will block the calling thread while the sound is playing. If you are
| > calling them in your main thread then it could easily make your app stop
| > responding until the PInvoke occurs.
| >
| > The PlaySound API call actually has a flag to indicate whether it
| > operates in synchronous or async mode.
| >
| > Also, as for threading in general, are you trying to update form
| controls
| > from a thread that doesn't own the form? That will cause application
| > instability on the .NET CF. There is a workaround for this called
| > "ControlInvoker" which if you dig around on the MS support site, you can
| > find. This lets you invoke methods on forms from threads that do not
own
| > the form.
| >
| > Hope that helps
| >
| > -- Erik
| > This posting is provided "AS IS" with no warranties, and confers no
| rights.
| > --------------------
| > | From: "Rick Winscot" <[email protected]>
| > | Subject: Threading with PInvoke Freezes Application
| > | Date: Mon, 18 Aug 2003 16:41:54 -0600
| > | Lines: 18
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| > | Message-ID: <[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.compactframework
| > | NNTP-Posting-Host: 205.127.17.136
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
| > microsoft.public.dotnet.framework.compactframework:31237
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
| > |
| > | Threading with PInvoke Freezes Application
| > |
| > | I am working on some apps with threading. In this particular app - the
| > | device becomes unresponsive (highly duplicatable) when calling an
audio
| > | function through PInvoke... I get similar results while calling
anything
| > | with
| > | PInvoke and using threads.
| > |
| > | Has anyone else experienced this kind of activity with threading? It
| > would
| > | be ever so helpful if the thread priority (.NET CF) was supported.
Hint
| > | Hint.
| > |
| > | Cheers,
| > |
| > | Rick Winscot
| > | rickly@zyche dot com
| > |
| > |
| > |
| >
|
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top