[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Catching Thread Creation

Posted on 2004-11-24
17
Medium Priority
?
312 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:gvector1
  • 7
  • 7
  • 2
  • +1
17 Comments
 
LVL 11

Expert Comment

by:jatinderalagh
ID: 12673899
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
 
LVL 11

Accepted Solution

by:
pratap_r earned 2000 total points
ID: 12675520
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
 
LVL 18

Expert Comment

by:armoghan
ID: 12680284
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:gvector1
ID: 12701167
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
 
LVL 18

Expert Comment

by:armoghan
ID: 12702540
gvector1,
Try the way present in above link I provided
0
 
LVL 11

Expert Comment

by:pratap_r
ID: 12703119
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
 

Author Comment

by:gvector1
ID: 12737937
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
 

Author Comment

by:gvector1
ID: 12820146
Anybody with any suggestions???????

Thanks,
Kendal
0
 
LVL 11

Expert Comment

by:pratap_r
ID: 12827348
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
 

Author Comment

by:gvector1
ID: 12831412
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
 
LVL 11

Expert Comment

by:pratap_r
ID: 12831852
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
 
LVL 11

Expert Comment

by:pratap_r
ID: 12831880
can you post the exception you get when you try to open the form again? ill see if i can debug it
0
 

Author Comment

by:gvector1
ID: 12832104
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
 
LVL 11

Expert Comment

by:pratap_r
ID: 12838187
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
 

Author Comment

by:gvector1
ID: 12841418
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
 
LVL 11

Expert Comment

by:pratap_r
ID: 12845493
ill try to rig up a small app to simulate your problem in the mean time.. keep me posted.
0
 

Author Comment

by:gvector1
ID: 12893090
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question