|
It's not the most efficient, but yes you can.
You should study streaming media by googling the 'net. We've also discussed it in this forum before. To find older threads, click "Search comments" at the top of this message board and search for "streaming".
More advanced algorithms are tolerant to a certain amount of data loss, sending encoded packets instead of reading the entire stream as an encoded file. There's much more involved for an efficient algorithm as well.
My recommendation is to use what's already available. Windows Media Encoder is free from microsoft.com and you can easily stream it to your client application using the Managed DirectX[^] assemblies, which utilize the compliant codecs (encoders and decoders) found on the system like WMA, WMV, DivX, MP3, MPEG, etc.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I am drawing lines of different colors based on a criteria. I have an If Else loop and when the panel paint event is called it selects the color specified in the else statement by default. Kinda overrides the color in the if statement. So all the lines turn out be blue. Here is the code:
foreach(Line l in Lines)
{
if(locallink!=null)
{
char charfileindex1='#';
int charfileindexlen1=locallink.Split(charfileindex1).Length;
string[] ss=new string[charfileindexlen1];
ss=locallink.Split(charfileindex1);
for(int i=0; i {
//int index=ss[i].IndexOf(dragimage);
if(checklinks(ss[i].ToString())> 0)
{
//draws red line
DrawAssocLine(l);
label4.Text="Red"+k.ToString();
k++;
}
else
{
//draws blue line
DrawLine(l);
label5.Text="Blue"+m.ToString();
m++;
}
}
}
}
Region r = getRegionByLine(line,p);
thumbnailpanel.Invalidate(r);
thumbnailpanel.Update();
r.Dispose();
|
|
|
|
|
if and else do not describe a loop; they are conditional statements.
What exactly is your problem? What is your question? I don't see where you've drawing with different Pen s and you didn't state what your problem was - only that you were having a problem.
If you need to draw with different Pen s, the best solution is to - if possible - instantiate those Pen s once and re-use them. If the code above is for your OnPaint override I can already tell your component will update slowly. Only paint what you have to, and try to avoid costing operations - like instantiating new objects - in your paint handlers. Cache what you can.
And always call base.OnPaint as the first operation in your handler (or around there - before you start painting). If you don't, part of the control may not be drawn (depending on what it is) and the Paint event will not be fired (so Paint event handlers will not be called).
If you are doing this in a Paint event handler, then consider extending whatever class you're painting now and overriding OnPaint . This gives you greater flexibility and is faster than invoking an event handler (or chain of event handlers).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
So what is your question? I would guess you dont want that all lines are painted in blue. But there is nothing such as a override from the else over the if block. To find your error the provided code is not enough. First of all check if your condidition ever gets true. Secondly check if your DrawLine and DrawAssocLine really paint lines in different colors. And third make sure that no two lines are exactly above each other (that could lead to a blue line overpainting a red line).
|
|
|
|
|
I have several windows openned of the same form class;
upon closing out the last mainform, I hid it, so the app doesn't exit;
thereafter, I create a new form; I repeat the
closing and opening of this
new form (the mainform is still hidden);
I have noticed that mem usage keeps going up?
Any help on what's going on? Corrections?
Should I try to Dispose/Release the hHWD's manually?
"Being smart is no good until you find out who else is smarter?"
|
|
|
|
|
It's not a memory leak it's just that the GC hasn't reclaimed the memory the form that gone out of scope.
Here's a test you can do... Instantiate and destroy the offending form about 10x's, then call GC.Collect() and see what happens.
|
|
|
|
|
It's recommended that you don't call GC.Collect except in dire circumstances. For any class that implements IDisposable - like many of the Windows Forms classes including derivatives of Control - you should call Dispose when done with the class instance. The using block statement in C# is helpful in this way.
This will release the native resources immediately instead of waiting of the object to be finalized which happens when the application is idle or memory is near exhaustion.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
You may also want to refer to this CP article[^] for a brief discussion of how and when to implement your own Dispose method - particularly with respect to suppressing finalization when Dispose is used.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Don't tell me - tell the other poster. I'm well aware of the disposable pattern[^] as Microsoft defines and implements it.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
My comment was associated with the context of yours, so the reply was attached under yours. I see no reason to create a peer comment, then reference your comment to achieve the same thing.
And yes, I'm positive you know all about implementing Dispose .
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Thanks. I'll be trying it out tonite.
"Being smart is no good until you find out who else is smarter?"
|
|
|
|
|
Hi
I wrote a C# application that export grid data to an excel workbook. The application works fine when I run it on my local machine and fail with "System.Security.SecurityException" error if I try to lunch it from a network drive folder.
How do I solve the problem? Is there easy to follow reading material about this on the web? most of my search are not getting me anywhere.
Thanks
|
|
|
|
|
The error you're encountering is most likely arising because you don't have launch permission for Excel on the remote machine.
Since you're executing your app from a remote share, when you attempt to launch Excel (unless you've done something to avoid it) you're launching it on the remote machine. If that's really what you are aiming for, you should be able to set launch permissions for Microsoft Excel by running dcomcnfg.exe.
Best of luck.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
None of that is true. First of all, the SecurityException is thrown because the permissions granted to managed code for a network address are few.
Second, when you launch an application from a remote machine the application files are loaded into memory on your local machine unless you're using Terminal Services (or something similar, like VNC).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
The previous post is incorrect. The problem you're having has to do with permissions granted to your managed code. Code Access Security (CAS) is a mechanism that grants permissions to managed code based on evidence. For managed code running over the LAN (Intranet), the default permissions are few. For code run over the Internet, the permissions are even tighter (in .NET 1.0 such code gets no permissions to run).
You need to grant your code based on evidence - like a UrlMembershipCondition using "file://SERVER/SHARE" - permissions to run.
Read Understanding .NET Code Access Security[^] here on Code Project for more information.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I have an integer, say 0x819A, which represents the Japanese shift-jis coded star character. How do I convert this to the System.Char? (that is the unicode encoding)
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
If you want to specify the character in code, use the \uXXXX notation in C# like string star = "\u819a"; . As you should notice, the character format uses a hexadecimal representation.
If you want to convert any bytes to a particular encoding, you use the System.Text.Encoding class that's appropriate, like the UnicodeEncoding (which you can get from Encoding.Unicode as well).
Since a char in managed code is actually a 2-byte character (wide character), you can simply cast it: char c = (char)0x819a; .
If you want to convert arbitrary characters you can also convert the 2-byte integer (short , or Int16 ) to a byte[] array and use UnicodeEncoding.GetString to decode the character:
byte[] buf = BitConverter.GetBytes(0x819a);
string s = Encoding.Unicode.GetString(buf); But there's an easier way than that, too, using the BitConverter class:
char c = BitConverter.ToChar(0x819a); The important thing is to understand just what a char is in native or manage code and about encodings.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello Heath,
Thanks for the response. It is a good attempt, but I have played with all these already
The main point in my post is that the number is the shift-jis coded.
What works is Chr in the Microsoft.VisualBasic.dll. You just wanna be a VB.NET programmer for after wasting half a day on C#.
Well, with Reflector, I was able to get the C# version of Chr to continue my work
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
If it uses a different encoding then create that instance of the Encoding you need. Taking a dependency on another assembly just to use Chr is absurd. Are you now going to bloat your software distribution and force that assembly on your clients?
It all comes down to encodings. If the character is encoded differently than UTF8 or Unicode, then use the right encoding:
Encoding enc = Encoding.GetEncoding(932);
string s = enc.GetString(BitConverter.GetBytes(0x819a));
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello Heath,
Thanks for the support.
Heath Stewart wrote:
Taking a dependency on another assembly just to use Chr is absurd. Are you now going to bloat your software distribution and force that assembly on your clients?
You really believe I will be doing that? Chr is a static and almost independent.
Heath Stewart wrote:
It all comes down to encodings. If the character is encoded differently than UTF8 or Unicode, then use the right encoding:
If you are using an international version of XP, just set the font of the Form to "MS Mincho" or similar with the character set to Japanese and view the output of your code snip in a paint handler as:
e.Graphics.DrawString(s, this.Font, Brushes.Red, 20, 20);
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
Paul Selormey wrote:
Chr is a static and almost independent.
It doesn't matter if it's static. There is no "static linking" like with native code. Or are you saying that you'll just duplicate what it does. I've done this for an old project for a GetDeviceCaps wrapper.
The character encoding is a different issue than the font issue, which I didn't realize you were having problems. Yes, a font file must have defined a glyph for that font, but how the character is encoded is a different matter. When you decode it you have a char . The cast I showed you initially would've worked had the character been ASCII (7-bit) or Unicode (native to .NET) encoded. Characters in .NET are all stored as Unicode, so you just need to make sure you decode it from the proper encoding. Whatever font you use should be based on what characters you expect.
In Windows XP several of them have a wide range of Unicode characters. Font files, BTW, are typically encoded for a particular encoding. For the Unicode font files, they are coded for Unicode encoded characters, of course.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Heath Stewart wrote:
Or are you saying that you'll just duplicate what it does. I've done this for an old project for a GetDeviceCaps wrapper.
That is the simply story.
public static char Chr(int CharCode)
{
if ((CharCode < -32768) || (CharCode > 0xffff))
{
throw new ArgumentException();
}
if ((CharCode >= 0) && (CharCode <= 0x7f))
{
return Convert.ToChar(CharCode);
}
int nTemp;
Encoding enc = Encoding.GetEncoding(932);
if ((enc.GetMaxByteCount(1) == 1) && ((CharCode < 0) || (CharCode > 0xff)))
{
throw new InvalidOperationException();
}
char[] chTemp = new char[2];
byte[] buffer = new byte[2];
Decoder decoder = enc.GetDecoder();
if ((CharCode >= 0) && (CharCode <= 0xff))
{
buffer[0] = (byte) (CharCode & 0xff);
nTemp = decoder.GetChars(buffer, 0, 1, chTemp, 0);
}
else
{
buffer[0] = (byte) ((CharCode & 65280) / 0x100);
buffer[1] = (byte) (CharCode & 0xff);
nTemp = decoder.GetChars(buffer, 0, 2, chTemp, 0);
}
return chTemp[0];
}
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
Hello,
I would like to do the following thing: Suppose I have a .Net program running. From another program I want to be able to get access to the first program's instantiated objects. My utlimate goal is to have something like a real time debugger where I can see the actual object's properties and fields values, without having to pause the program and use the VS debugger. Right now I have done something that can do exactly what I describe here, however from the program I want to debug I need to give reference to the objects I want to analyse to my real time debugger.
I realy want to achieve the same thing with my real time debugger but without having to have a link between the debugge and and the debugger.
I have investigated the following:
- Use Process.GetProcesses() then get a module from the process with: ProcessModuleCollection modules = process.Modules.
From there I don't know where to go....
Any Ideas ?
- Dany McCarthy -
|
|
|
|
|
A process is not the same as an AppDomain , in which the managed objects are actually hosted. For this you need to implement .NET Remoting, which you can read about at http://msdn.microsoft.com/library/en-us/cpguide/html/cpconaccessingobjectsinotherapplicationdomainsusingnetremoting.asp[^]. Just having a Process instance (in the native world, this is a process handle, or HANDLE ) won't help you acheive that end.
If it's a debugger or debugger-like application your after, then write one. It's actually not too difficult if all you want to do is examine objects. View the search results for managed debugger[^] for a large list of examples about how to implement a debugger, as well as some blog entries from developers on the CLR team.
This will require native code and can tell a lot more about an object than what you can get through managed code, even with .NET Remoting - which would require that you establish a remoting infrastructure for both applications.
You can use other IPC (inter-process communications) mechanisms to communicate between applications, but .NET Remoting is the recommend way, and is the best way to marshal managed objects across application boundaries, rather than marshaling memory through global locks and other ways that you'd have to do in managed code. Keep in mind that what managed applications see is much different than what's actually on the heap or in the stack for managed objects. That managed code is JIT'd to native code, which works much differently under the covers.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks Heath, for sure I do not want to go through the unmanage solution. I think I will keep going with what I've done so far. I already planned to implement remoting to do real time remote debugging. I will send an article about my results if they are concluant.
Best regards,
Dany McCarthy
|
|
|
|