|
previously, i had an application that use a COM object to grap image from web cam. i try to enhance my application by using the Windows Media Encoder 9 Series SDK to do live video streaming.
i realize that whenever i stop my image capturing thread and run WM live video streaming thread, my application has no problem at all the access the web cam device. however, whenever i try to stop WM live video streaming thread, the COM object unable the use the web cam device. it seems that the camera device still hold by the WM thread. the WM thread goes like this......
-----------------------------------------------------------------------
public void StartWM()
{
if(WMThread != null)
{
if(WMThread.IsAlive)
{
StopWM();
}
}
if(cameraThread != null)
{
if(cameraThread.IsAlive)
{
StopCamera();
}
}
WMThread = new Thread(new ThreadStart(_StartWM));
WMThread.Priority = ThreadPriority.Lowest;
WMThread.Start();
}
public void StopCamera()
{
if(cameraThread != null)
{
cameraThread.Abort();
while(cameraThread.IsAlive);
cameraThread = null;
}
}
public void StopWM()
{
if(WMThread != null)
{
WMThread.Abort();
while(WMThread.IsAlive);
WMThread = null;
}
if(Encoder != null)
{
Encoder.Stop();
//HOW TO MAKE SURE ENCODER
//IS COMPLETELY RELEASE ITS //WEB CAM DEVIDE HANDLE
//BEFORE IT PROCEEDS TO
//NEXT //STATEMET???????
//while(Encoder.IsAlive); <-
//- of course this
//wont work
Encoder = null;
}
}
private void _StartWM()
{
try
{
// Create WMEncoderApp and WMEncoder objects.
if(Encoder == null)
{
Encoder = new WMEncoder();
}
//encoder initialize
//code goes here for live
//video
//broadcasting
//Start the encoding
//process.
Encoder.PrepareToEncode(true);
Encoder.SynchronizeOperation = false;
Encoder.Start();
}
catch(Exception ex){}
}
-----------------------------------------------------------------------
whenever i wish to start the camera thread, i must first make sure the wm thread first release its handle to web cam. hence, i used to call StartCamera.
public void StartCamera()
{
if(WMThread != null)
{
if(WMThread.IsAlive)
{
StopWM();
}
}
if(cameraThread != null)
{
if(cameraThread.IsAlive)
{
StopCamera();
}
}
cameraThread = new Thread(new ThreadStart(_StartCamera));
cameraThread.Priority = ThreadPriority.Lowest;
cameraThread.Start();
}
-----------------------------------------------------------------------
inside _StartCamera, i will construct a camera COM object and capture image using that COM object. however, the COM object unable the use the web cam device whenever it wants to grap image
i suspect that the web cam is still hold by encoder. how can i make sure web cam is released by encoder after i call Encoder.Stop()?
thank you.
regards
yccheok
|
|
|
|
|
i had build a light weighted http server and recently realize that there is some bugs inside.
in my constructor, i initialize the TcpListener and the thread for receiving incoming request as follow:
----------------------------------
myListener = new TcpListener(port);
myListener.Start();
//start the thread which calls the method 'StartListen'
myThread = new Thread(new ThreadStart(StartListen));
myThread.Start() ;
----------------------------------
in my StartListen
----------------------------------
while(isRunnable)
{
//Accept a new connection
Socket mySocket = myListener.AcceptSocket() ;
if(mySocket.Connected)
{
//make a byte array and receive data from the client
Byte[] bReceive = new Byte[1024] ;
int i = mySocket.Receive(bReceive,bReceive.Length,0); //BUGS??
// rest of the code goes here
----------------------------------
sometimes, when i use a web broswer making an HTTP/GET request, my web broswer takes 5 minutes to download the contents from the computer that run light weighted server(LWS) and still get no responde. it seems that it can establish a TCP/IP connection to the LWS but get no response from the LWS.
finally, i realize that LWS will halt at the line.
-----------------------------------
int i = mySocket.Receive(bReceive,bReceive.Length,0); //BUGS??
-----------------------------------
this happen "sometimes". where "sometimes" LWS works fine and "sometimes" LWS dont :P
can anyone point me out how can i solve this problem? thank you in advance.
regards
yccheok
|
|
|
|
|
hi, all
How to invoke DLL in C#?
thanks very much
|
|
|
|
|
This column should help:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp09192002.asp
|
|
|
|
|
I'm having a problem double buffering my form. I use
<br />
SetStyle(ControlStyles.UserPaint, true); <br />
SetStyle(ControlStyles.AllPaintingInWmPaint, true);<br />
SetStyle(ControlStyles.DoubleBuffer, true);<br />
and the last line gives me a System.ArgumentException. The additional info is Invalid argument used... I checked out the MSDN and it says to use them like this. They are inside the Form() constructor. Anybody have any clue why this is happening?
|
|
|
|
|
public Form1()
{<font color="green">
<code>InitializeComponent();</code>
<font color="green">
<code>SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);</code>
}
This code itself does not cause a compile time error, as I placed the code inside a blank application itself and it compiles fine, you may have other issues inside your constructor.
Nick Parker
Not everything that can be counted counts, and not everything that counts can be counted. - Albert Einstein
|
|
|
|
|
I figured it out I was looping the call to the OnPaint() and inside I used a graphics object. I mistakenly Dispose()'ed of the PaintEvenArg instead of the graphics object.. I guess it doesn't like that because I took the call to Dispose() out and it works fine now
|
|
|
|
|
You have to do it like this:
SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true);
Each successive call to SetStyle eleminates the previous setting and changes it to the new one. So, essentially, your just calling SetStyle(ControlStyles.DoubleBuffer). Because double buffering has to be used in conjunction with UserPaint and AllPaintingInWmPaint, you get the error Invalid Argument Used. Using a bitwise or, you combine the values of all three into one setting.
Hope this helps.
|
|
|
|
|
Hi!
I'm looking for some samples how to write an IRC client in C#.
Have someone any samples?
thx!
|
|
|
|
|
|
Hi,
I've have a tree view control that displays a scene graph (a collection of polygons, materials etc). I would like each type of object to have it's own context menu, for example, if the user right clicks on a node, it should check the 'Tag' property of the node, and if it is of a certain type it should show a certain context menu. Do I have to create a class derived from TreeView for this, or can I do it another way?
Dave Kerr
focus_business@hotmail.com
www.focus.esmartweb.com
|
|
|
|
|
|
Heck, I'm still trying to set up the djgpp thingy so I can do the "hello world " thing.
A lot of basic and a bit of pascal. None of which works in windows.
I need a plotter driver to run a home made plotter. It's a simple one run from the
printer port. Nothing fancy at all. A lot of other "hobby" folks would like to get it too.
I woulldn't mind trying to write it myself as a excuse to learn more about C.
Anybody interested in helping?
I made the interface boards and they work fine in dos mode with,yeck, basic.
Steppers are 400 steps per rotation 119 in.oz.
No, I don't realy expect anybody to come up for air on this.
Thanks anyway.
GaryR
|
|
|
|
|
I would start simpl (Hello World), then work your way up to the Plotter Driver. When you have questions, this is a good place to post your problems. Have fun!
Joan
|
|
|
|
|
Thanks Joan for the fast reply. Simple is the key word for sure.
It toke for ever to find the most basic starting level info on working with the printer and con ports.
For others that read this looking for the same. A lot of surplus electroics places have a book,
Controling the World with Your PC by Paul Burgsman. It costs like $35 and is well worth it. It has a disc
with excutables as well as hard copy in basic,pascal, and c. This is in dos mode not windows.
I want to take it into windows. No, I don't have VB, only wish I did.
Between the book and this forum, I don't expect many problems. The chore will be getting it into a GUI
so somebody other than myself can easly use it. I'm thinking cheap shareware or freeware.
At the moment the most popular method is to use the hp7475a driver and plott to file, them use a dos
program to print the plt file on the homemade plotter through the paralle (printer) port.
The mechanics and electronics were easy, that I have a degree in. Programing for windows
will be........interesting.
GaryR
|
|
|
|
|
How to create an image list from a resoruce biutmap.
It's along the lines Bitmap.FromResource, and Imagelist.Images.AddStrip, but I'm lacking some syntax here.
Also, I can add a "resource template" to the project, but the "Resource View" tab remains empty. What's that?
If I could find a souvenir / just to prove the world was here [sighist]
|
|
|
|
|
Here is one way to do it. First, make sure your image resource is marked as "Embedded Resource".
Assembly thisAssembly = Assembly.GetAssembly(Type.GetType("Sample.Namespace.SomeForm"));
Stream bmpStream = thisAssembly.GetManifestResourceStream(Sample.Namespace.ResourceName");
Bitmap bmp = new Bitmap(bmpStream);
ImageList.Images.AddString(bmp);
|
|
|
|
|
Hi,
I've been having loads of problems with collections in C#. Up to now, my main class in my program has stored large amounts of data (vertices, polygons etc) in ArrayList's. I'd like to be able to use the Collection Editor from the properties window though, and to do that I realise I need a specific collection for each object. However, I've tried deriving from CollectionBase, and half the function's I've used with ArrayList don't work, then I tried deriving from ArrayList and the program crashed.
I'd really like to just derive from ArrayList and make the collection type specific, can I do this? Or do I have to derive from CollectionBase, and if so, what code must I implement to make it work like ArrayList? I know where to go from there, using custom collection editors, but first I need my custom collection!
Any Ideas?
Dave Kerr
focus_business@hotmail.com
www.focus.esmartweb.com
|
|
|
|
|
Here's all you need (you can obvious add some more methods):
public class MyTypeCollection: System.Collections.CollectionBase
{
public MyTypeCollection(){}
public virtual void Add(MyType value)
{
this.List.Add(value);
}
public virtual MyType this[int index]
{
get {return (MyType) this.List[index];}
set {this.List[index] = value;}
}
public virtual void Remove(MyType value)
{
this.List.Remove(value);
}
}
Nice typed collection with Collection Editor support.
DBHelper - SQL Stored Procedure Wrapper & Typed DataSet Generator for .NET
|
|
|
|
|
Cheers that worked great! I didn't have to change any of the code at all, just replaced 'ArrayList' with 'VertexCollection' and it worked fine.
Thanks very much!
Dave Kerr
focus_business@hotmail.com
www.focus.esmartweb.com
|
|
|
|
|
I am planning a ROM database in C# as hobby project. It may be usefull in retrieving big amounts of non transactional data from CD-ROM or disk file. I know Ms Access is an alternative but as I said it is a hobby project, more Access is not safe enough and brings a lot of overhead.
I may start with saving data into dataset objects, so that when I retrieve it , I can bind it into my win controls right away, anyway I would be retrieving them from database in datasets anyway.
I could save my data into dataset objects and serialize them but they become too big , and retrieving just one line of code would require loading a big file into memory.
Or I can split data and save chunks into numerous dataset objects and putting all these objects in a random access file, than building a hash table / index and saving it into the database. I assume this would minimize schema troubles and shift responsibility to ADO.NET in managing schema in Dataset.
I want your advise on this subject, may be totally different suggestions.
|
|
|
|
|
Is there a way to programmatically move a splitter control? I tried setting it's location, didn't work. I tried setting the size of one of the panels but that didn't work either.
"Outside of a dog, a book is Man’s best friend. And inside of a dog, it’s too dark to read."
-Groucho Marx
|
|
|
|
|
Say you want the panels divided vertically with a splitter control in between.
Dock the panelLeft as Fill
Dock panelRight as Right
Dock the splitter as Right
Programmatically change the size of panelRight with panelRight.Width
This should work.
When you come to a fork in the road, take it! Y. Berra
|
|
|
|
|
Thanks, but it doesn't work.
Form f=new Form();
Panel pf=new Panel();
pf.Dock=DockStyle.Fill;
f.Add(pf);
Splitter s=new Splitter();
s.Dock=DocStyle.Top;
f.Add(s);
Panel pt=new Panel();
pt.Dock=DockStyle.Top;
f.Add(pt);
I have a form with two panels and a splitter inbetween. I can click on the splitter and move it around ok. when I change the size of either or both of the panels, their size does change, but the splitter stays put. If any gap is created it just gets the background color of the Form.
"Outside of a dog, a book is Man’s best friend. And inside of a dog, it’s too dark to read."
-Groucho Marx
|
|
|
|
|