473,396 Members | 2,087 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,396 software developers and data experts.

Thread.Susspend

Hi,
I create a thread which load DLL and have DLL function call,this Dll
function takes a lot of time.
My Question is , if I request Thread.Susspend(), and the thread is inside
the Dll function (Dll function not finished yet, and thread function wait for
this function (DLL)call to compleate), what will happen ? is this will
susspend also the Dll function execution ? or will delay the susspend untill
this function returned ?

Thx
Nov 17 '05 #1
7 1869
> this function (DLL)call to compleate), what will happen ? is this will
susspend also the Dll function execution ? or will delay the susspend
untill
this function returned ?

It will stop the thread, wether it's running your code, DLL code, or
waiting for return information.

You have to resume the thread for work to continue.

Greetings,
Wessel
Nov 17 '05 #2
Hi,

I think that Suspend will suspend only when thread is in safe (managed)
state - this rules out unmanaged execution suspension.
Anyway, it is not a good practice to use Thread.Suspend at all as it is
unpredictable - instead use synchronization mechanisms.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
SLODUG - Slovene Developer Users Group www.codezone-si.info

"[Yosi]" <Yo**@discussions.microsoft.com> wrote in message
news:B5**********************************@microsof t.com...
Hi,
I create a thread which load DLL and have DLL function call,this Dll
function takes a lot of time.
My Question is , if I request Thread.Susspend(), and the thread is inside
the Dll function (Dll function not finished yet, and thread function wait
for
this function (DLL)call to compleate), what will happen ? is this will
susspend also the Dll function execution ? or will delay the susspend
untill
this function returned ?

Thx

Nov 17 '05 #3

"[Yosi]" <Yo**@discussions.microsoft.com> wrote in message
news:B5**********************************@microsof t.com...
Hi,
I create a thread which load DLL and have DLL function call,this Dll
function takes a lot of time.
My Question is , if I request Thread.Susspend(), and the thread is inside
the Dll function (Dll function not finished yet, and thread function wait
for
this function (DLL)call to compleate), what will happen ? is this will
susspend also the Dll function execution ? or will delay the susspend
untill
this function returned ?

Thx


If you mean your thread is executing a native code DLL function, then the
Thread.Suspend call will wait until the function returns from unmanaged
code. But you should NEVER use Thread.Suspend/Resume, it's way to dangerous
to use and these methods will be removed from the next version of the
framework. You should use managed synchronization primitives like
Monitor.Enter, Monitor.Wait , Monitor.Pulse, or WaitHandle.WaitOne instead.

Willy.

Nov 17 '05 #4
> If you mean your thread is executing a native code DLL function, then the
Thread.Suspend call will wait until the function returns from unmanaged
code.


Interesting, could you explain that in more detail?

I thought Thread.Suspend would call the ::SuspendThread() API, which ought
to stop a native code DLL function from executing.

Greetings,
Wessel
Nov 17 '05 #5

"Wessel Troost" <no*****@like.the.sun> wrote in message
news:op.suiu09wef3yrl7@asbel...
If you mean your thread is executing a native code DLL function, then the
Thread.Suspend call will wait until the function returns from unmanaged
code.


Interesting, could you explain that in more detail?

I thought Thread.Suspend would call the ::SuspendThread() API, which ought
to stop a native code DLL function from executing.

Greetings,
Wessel


The Thread.Suspend service in the CLR calls Win32 SuspendThread() API when
it's safe to call it from the CLR's point of view, that is when the code has
reached a safe point (in managed code) for the GC to run. When your thread
runs in unmanaged code land, the CLR is no longer controlling the execution
environment so it's considered dangerous to suspend a thread cold (it's even
dangerous to call SuspendThread in pure unmanaged code).

When running managed code you should never forget that the CLR (EE, JIT, GC
etc...) controls the run-time environment and the services called from the
underlying OS. That's why it might be 'dangerous' to bypass the CLR (and/or
the FCL) and call directly into Win32 through PInvoke to execute certain OS
services.

Willy.


Nov 17 '05 #6
> The Thread.Suspend service in the CLR calls Win32 SuspendThread() API
when
it's safe to call it from the CLR's point of view, that is when the code
has
reached a safe point (in managed code) for the GC to run. When your
thread
runs in unmanaged code land, the CLR is no longer controlling the
execution
environment so it's considered dangerous to suspend a thread cold (it's
even
dangerous to call SuspendThread in pure unmanaged code).

Thanks for the explanation.

The documentation says SuspendThread is a "debugger" facility, and should
not be used for thread synchronisation. It also says:

Calling SuspendThread on a thread that owns a synchronization object, such
as a mutex or critical section, can lead to a deadlock if the calling
thread tries to obtain a synchronization object owned by a suspended
thread.

Sounds like it's a good function to avoid :)

Greetings,
Wessel
Nov 17 '05 #7
OK,
I try other option but I still miss somthing , by handle the stat by
parameter of thread,from the father (FORM) when user click on susspend I
change the handle to be suspenrequest, in the thread(call DLL function) after
returning from Dll function call , the thread read the value of the handle if
suspendrequest I do Thread.CurrentThread.Susspend. and change the father
handle stat to be susspend,if not I call Dll function again (this is the
thread, call Dll function in loop).

If this Ok , I have a problem! , when user click on susspend I change the
state to susspenrequest,and wait to thread become susspeneded by read the
thread stat. in this case I sould wait in loop without doing any thing, but
if I do the following :

threadHandler.Susspend();
//Wait for Thread to susspend
do
{
read state if susspend then break;
}
while(true)

the thread(DLL) will not get focuse and it will never continue I don't know
whay ?, why that? the application will stuck in this loop and never continue
execution the thread.

If I try to use Sleep it also Sleep the thread(DLL), How I solve this problem?
Why I can't use Thread.Sleep in the click function inside while as following ?
threadHandler.Susspend();

//Wait for Thread to susspend
do
{
read state if susspend then break;
Thread.Sleep(200);
}
while(true)

Yosi.
"Miha Markic [MVP C#]" wrote:
Hi,

I think that Suspend will suspend only when thread is in safe (managed)
state - this rules out unmanaged execution suspension.
Anyway, it is not a good practice to use Thread.Suspend at all as it is
unpredictable - instead use synchronization mechanisms.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
SLODUG - Slovene Developer Users Group www.codezone-si.info

"[Yosi]" <Yo**@discussions.microsoft.com> wrote in message
news:B5**********************************@microsof t.com...
Hi,
I create a thread which load DLL and have DLL function call,this Dll
function takes a lot of time.
My Question is , if I request Thread.Susspend(), and the thread is inside
the Dll function (Dll function not finished yet, and thread function wait
for
this function (DLL)call to compleate), what will happen ? is this will
susspend also the Dll function execution ? or will delay the susspend
untill
this function returned ?

Thx


Nov 17 '05 #8

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

Similar topics

14
by: adeger | last post by:
Having trouble with my first forays into threads. Basically, the threads don't seem to be working in parallel (or you might say are blocking). I've boiled my problems to the following short code...
4
by: Gilles Leblanc | last post by:
Hi I have started a small project with PyOpenGL. I am wondering what are the options for a GUI. So far I checked PyUI but it has some problems with 3d rendering outside the Windows platform. I...
7
by: Ivan | last post by:
Hi I have following problem: I'm creating two threads who are performing some tasks. When one thread finished I would like to restart her again (e.g. new job). Following example demonstrates...
4
by: Matthew Groch | last post by:
Hi all, I've got a server that handles a relatively high number of concurrent transactions (on the magnitude of 1000's per second). Client applications establish socket connections with the...
5
by: Razzie | last post by:
Hi all, A question from someone on a website got me thinking about this, and I wondered if anyone could explain this. A System.Threading.Timer object is garbage collected if it has no...
16
by: droopytoon | last post by:
Hi, I start a new thread (previous one was "thread timing") because I have isolated my problem. It has nothing to do with calling unmanaged C++ code (I removed it in a test application). I...
1
by: [Yosi] | last post by:
Hi, As I read A thread can be in more than one state at a given time,and I cant use bit Mask to get spicific stat for example I have a thread which is in more than one stat at time, I want to know...
2
by: [Yosi] | last post by:
I have C# application, in main form I made thead... User click on susspend button which cause to suspend the thread, in the button fuction: mThread.Susspend(); What I should do to wait in this...
9
by: mareal | last post by:
I have noticed how the thread I created just stops running. I have added several exceptions to the thread System.Threading.SynchronizationLockException System.Threading.ThreadAbortException...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.