Catching Thread Creation

Is there anyway to catch threads once they are created so as to keep a list of all threads created during a certain point within my application.  Reason being is that I have an application in which threads are created by some com objects and for some reason they are never released even though the com object is.  I would like to keep a list of the threads that are created and then process that list to make sure the threads are terminated.  Can anyone help?????????

Thanks,
Kendal
gvector1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jatinderalaghCommented:
Hi kendal

suggestion : I don't have the capturing devices so i can't test. But try disposing your panel on which you are capturing.
And create new panel everytime (in run time) when you start capturing.

hope it will work
Jatinder
0
pratap_rCommented:
You can get a list of threads that your current application is using but it will be difficult to keep track of, my suggestion for your problem will be to go for Application Domains, for example create a new domain and execute your methods there and once you are done with the COM objects probably you can destroy the application domain. This way you can make sure that your threads are terminated. If you still want to use the approach of keeping track of the threads do let me know.

Have Fun!
Pratap
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
armoghanCommented:
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

gvector1Author Commented:
I know a little about application domains.  Is there a quick code snippet you could post on how to execute a few methods on a new application domain?????

Thanks,
Kendal
0
armoghanCommented:
gvector1,
Try the way present in above link I provided
0
pratap_rCommented:
heres some example
http://www.codeproject.com/dotnet/AppDomainMemImprovement.asp

more on app domains,
http://weblogs.asp.net/cbrumme/archive/2003/06/01/51466.aspx

process internals and tracking down threads (both managed and unmanaged)
http://msdn.microsoft.com/msdnmag/issues/04/10/NETProcessBrowser/default.aspx

Have Fun!
Pratap
0
gvector1Author Commented:
I have looked at this and have not found a way to accomplish what I need.  I have a form which contains a button.  When I click that button, a new window opens up (via ShowDialog) and starts a preview of what is being viewed on the pc connected camera.  Once the picture is taken, it is either accepted or cancelled and the DialogResult sent back to the calling form.  My problem is that I am using a DirectShow through Interop library container below:

http://www.codeproject.com/cs/media/directshownet.asp

For some reason when I close the window, and try to reopen it, I get an error.  I believe it to be because something is not shutting down completely, although everything that is created with the code is also released.  That is why I was looking to using the above suggestion of using an appDomain so as once I am done with the picture taking code, I can release the appDomain.  Would that work????????  If so, won't I have to make the picture-taking form into an executable of its own in order to be used with an AppDomain???????  I basically need it to behave exactly like it does as a form.

Thanks for all assistance and suggestions,
Kendal
0
gvector1Author Commented:
Anybody with any suggestions???????

Thanks,
Kendal
0
pratap_rCommented:
sorry i guess i lost track of this thread...

kendal, you dont have to create a new exe.. all you have to do is create a new appdomain and load  your dll's into it using createinstance and when you are done with the processing destroy the appdomain.

you could also try using CreateComInstanceFrom method for com objects.

on a side note, why dont you try using directx for .net? there is an sdk available in MS website. you dont have to deal with interops this way...

Have Fun!
Pratap
0
gvector1Author Commented:
I have looked at the directx for .net, but it seems it has everything except for directshow.  DirectShow seems to have everything I would need to accomplish the task at hand, but the only place I found anything on it in DirectX.NET was for C++, not C#.  Any suggestions on what I should use as far as any of the options in DirectX, or is there a way to use DirectShow without the interop in C#????  As far as the appdomain approach goes, what you are saying is that I can have all of my interop code created into a dll and load it into a new appdomain, and when I execute any of the methods within that dll it will execute in the new appdomain???????  Is that correct????????  Am I on the right track with the following code????

ex:
AppDomain ad = AppDomain.CreateDomain("myDomain");
ad.CreateInstance("myDLL",?????????);  //I cannot find an example of this to help me determine what goes here.
//I am guessing after the previous lines of code that when I call upon a method that is loaded into the AppDomain, it will execute within that domain.  Is that correct??????

Thanks,
kendal
0
pratap_rCommented:
yes you are on the right track..

check this link.. there is a code snippet of what you are trying to do..
http://blogs.msdn.com/junfeng/archive/2004/02/09/69919.aspx

0
pratap_rCommented:
can you post the exception you get when you try to open the form again? ill see if i can debug it
0
gvector1Author Commented:
The exception I am getting says the following

Could not set up graph!
The parameter is incorrect.

I debugged the code to the following line of code:

hr = capGraph.RenderStream( ref cat, ref med, capFilter, null, null );

I have checked everything I could.  What I am kind of thinking is that on the RenderStream line of code, that the last parameter is left null in order to use the default video renderer.  I am thinking that maybe when everything is released when the form closes that the default video renderer is not being released.  That is just my thinking though.  That is why I was going to try and run everything under an AppDomain so that once the form closes the appdomain can be unloaded and everthing will definitely be unloaded.

Thanks,
Kendal
0
pratap_rCommented:
are the other parameters fine? because afaik the videorenderer used is non blocking and does not have to be released explicitly. eitherway appdomains should work fine, but they will be costly interms of cpu times.
0
gvector1Author Commented:
As far as debugging goes, the cat and med parameters are the same every time as they are GUID's.  The capFilter parameter seems a valid parameter every time, here is the code that declares the capFilter

Guid gbf = typeof( IBaseFilter ).GUID;
mon.BindToObject( null, null, ref gbf, out capObj );
capFilter = (IBaseFilter) capObj; capObj = null;

I can't see where any other parameter would be invalid.  I am still trying to determine exactly how to code and use AppDomain correctly in my code.  I am going to try to get AppDomain to work and will post back with results.  Any other information that you may come across is greatly appreciated and your help thus far is appreciated as well.

Thanks,
kendal
0
pratap_rCommented:
ill try to rig up a small app to simulate your problem in the mean time.. keep me posted.
0
gvector1Author Commented:
Thanks for all of the help pratap.  I have actually found a different and more simple approach to the problem.  I am still attempting to use AppDomains to fix the current problem in my spare time.  I appreciate all of the assistance you have given and you have well earned the points.  If you are able to rig up a small app, I would love to see it.

Thanks again,
Kendal
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.