|
I looking for a way to signal a function in a running thread to stop what is doing, clean up, and then end. The thread runs testing code that I don't have control over. Since I don't have access to this section of code there is no way for me to put checks in for a flag to end a test run. I check a flag just before a function runs the unknown code and just after to stop the thread, this works. But some of the unknown code can run for hours and I need a way to throw an exception, signal, or interrupt the function that executes this code in the thread. The interrupt would be coming from the program that started this testing thread.
// This runs an individual test.
method.Invoke( test, null ); <<-- This is where I need to get into.
Thanks
Mark
-- modified at 8:15 Thursday 20th October, 2005
|
|
|
|
|
Unless a thread is designed to be interupted or killed from any location, it is generally a bad idea to stop a thread of execution from the outside. You can easily leave whatever the thread is touching in a bad state by just killing the thread wherever. For instance if you are writing data to media you could be in the middle of the file when you externally tell the thread to end leaving you with junk data.
I would first look to see if there is a way to redo your application in such a way to avoid having the need to kill threads. But if you really really really want to halt a thread, use Abort which will generate a ThreadAbortException .
Hint: you will still need to Join even after you use Abort .
|
|
|
|
|
Is there a way I can?
1. Throw an exception to the thread. So I catch that exception within the thread.
2. Or catch the ThreadAbortException in the thread.
Thanks
|
|
|
|
|
RochesterMark wrote: Throw an exception to the thread. So I catch that exception within the thread.
While you can't inject arbitrary exceptions into the thread code, if you know the code that the thread is executing, you can make those methods throw exceptions. Not an elegant solution.
RochesterMark wrote: Or catch the ThreadAbortException in the thread.
You can't. That would break the whole purpose of ThreadAbortException, won't it? What if you just catch it and proceed like nothing happened?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Basically yeah what Senthil wrote.
RochesterMark wrote: 1. Throw an exception to the thread. So I catch that exception within the thread.
No. Threads by definition hold their own stack. Any reference, including exceptions, generated in one thread are meaningless in another. Trying to mess with another stack frame is of dubious value no mater what you are trying.
What you are thinking about is a concept like a "signal" or events or other cross threading data ideas (ala. IPC, shared memory segments, etc). I avoided mentioning these things because they are really somewhat advanced.
RochesterMark wrote: 2. Or catch the ThreadAbortException in the thread.
Once again, exception generated in one thread is meaningless in another. Trying to catch an exception that isn't in your stack frame is a weird concept anyway. Throwing an exception modifies the stack of the current context. Catching the exception of another thread is as "crazy" as making another thread call a function in the middle of execution.
It is my experience that most of the time when someone is asking a question that violates fundemental principals of a system, in this case Threading, they need to seriously reevaluate what is going on. Trying to force a thread to actively manipulate the stack of another thread is simply not sane even if the runtime allowed it so why would a software engineer want to write software that does this?
|
|
|
|
|
i want some code exercises because i haven't been programming for 3months know !!!where can i get them??????????????????//
|
|
|
|
|
just go through some exercises of walk through in MSDN
and u then can wrap up some articles to post here .... ;(
<< >>
|
|
|
|
|
|
Just read the questions in this forum and code up answers. :->
Matt Gerrans
|
|
|
|
|
True enough. thats how i started learning
Aim small, miss small...
|
|
|
|
|
hi all !
How to check all records in all pages across grid with a single click..and those check boxes has to maintain the state in paging of grid..
kris
|
|
|
|
|
Hi,
How can I check an instance of class A is implementing an interface B in program ?
Thanks
|
|
|
|
|
if (MyAObject is B) ...
---
b { font-weight: normal; }
|
|
|
|
|
i've this string: "abcdefgh"
i want to create a crypting key for the cryptostream, i've tryed ASCII.getBytes("abcdefgh") bu t get error!
|
|
|
|
|
What kind of error?
That is a very weak key to use for cryptography. Use the crypto provider to create a real key instead.
---
b { font-weight: normal; }
|
|
|
|
|
in this way i get a byte array.
so if i need to give the file to my friend i need to tell him the key.
How if is it just a byte array?
|
|
|
|
|
You can use any representation of the byte data you like. One obvious would be the hexadecimal representation of each byte.
---
b { font-weight: normal; }
|
|
|
|
|
Hello, I need help with the following problem, please.
I am using C# and DirectX 9 to show MPEG-2 video files within a Windows form. Unfortunatelly I often do not get the correct duration of the file when checking the "duration" property, e.g. a 18 second clip assumes to be only 4 seconds long. So all these videos stop playing too early.
Also, it is not possible to jump to certain positions in the video. If I add a new value (e.g. "AverageFrameLength") to the "CurrentPosition" the displayed video proceeds only every n-th frame and skips all frames in between.
I did not have these problems with a MPEG-1 video, for example. With those, everything worked fine.
Does anyone have an idea, why the durations are gathered incorrectly and how I handle this? I searched the whole web for a solution, but it seems nobody else has ever had a problem like this.
It seems that there are two things that seem have an influence on this situation.
1.) If these video files are converted to use a constant bit rate the duration property seems to get at least get the correct value. Moving from frame to frame still does not work reliably. But as conversion of all files increases their sizes significantly, this ist not an option anyway.
2.) Also, this does not work with every MPEG-2 codec. To receive correct duration values, I first needed to remove the "Moonlight Elecard" MPEG-2 Codec from my system. After that it used another codec automatically. In my case this is the "MPEG-2 Demultiplexer" (Which - I guess - belongs to the DirectX installtion).
Of course, I cannot know what codecs might be installed on a destination system for my application, and even worse, I cannot simply remove a codec from the system just because my app does not like it...
Any ideas?
|
|
|
|
|
Hello Sensei,
i had similar problems with divx files. It it figures out that the problem depends on the codec configuration. Perhaps this leads you forward
Greets Snow
|
|
|
|
|
I set Format property of DefaultCellStyle property of an instance of DataGridViewTextBoxColumn to N2 But it doesnt work.
N2 means Numeric 2 digit number (1,254.56 etc)
I aim to create a numeric DataGridViewTextBoxColumn . What can i do else?
|
|
|
|
|
How can i check which users are logged into the network?
marcelw
-- modified at 6:16 Thursday 20th October, 2005
|
|
|
|
|
User don't login to a network, they login to servers. What kind of servers? And from where do you want to determine this information? Client-side or server-side?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Basically I want to check if the user is at the office, logged in at his desk. It will need to be an application running on one machine.
marcelw
|
|
|
|
|
That depends on the server your running this from. Are you talking about checking this in a login script, a web service, web application, insert situation here, ...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi,
My problem is as below,
1. I open a window form in .NET
2. place a panel A on the form, where the panel's paint method was overrided
3. on the panel A, I placed a tab control
4. on the tab control, I placed another panel B with overrided paint method.
And I repaint all the two panels A and B (by calling its Refresh() method), but only get the panel A refresh, while panel B has no effect.
Why ???? I have tried method like Update(), invalidate(), validate(),
but all have no effect on panel B.
Thanks
|
|
|
|