|
you mean ,
try
{
int i=0;
int j=2;
if(i==0)
{
throw new ArgumentNullException();
}
int k=j/i;
}
catch(Exception e)
{
messagebox.show(e.Message);
} We are haven't bug,just temporarily undecided problems.
|
|
|
|
|
jojoba2011 wrote: the value or Parameter that cause error in try block?
If you're asking what I think you are, you can't get that detailed of a message.
|
|
|
|
|
I exactly want this message :
line 5 exception occured
i=0 made this error
|
|
|
|
|
Stack trace will have these details. You have to parse the stack trace and extract this information. Best wishes,
Navaneeth
|
|
|
|
|
Move i outside the try/catch block so it is visible in all sections, something like:
int i;
try
{
i=0;
int j=2;
int k=j/i;
}
catch(Exception e)
{
string msg = "i = " + i + " " + e.Message;
messagebox.show(msg);
} txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
i=0 didn't cause the Exception; it's j/i .
You could put the three statements each in its own try/catch.
You could keep track of where you were in the process:
int x;
try
{
x=0;
int i=0;
x=1;
int j=2;
x=2;
int k=j/i;
x=3;
}
catch(Exception e)
{
string err="";
switch(x)
{
case 0: err = " caused by i=0" ; break ;
case 1: err = " caused by j=2" ; break ;
case 2: err = " caused by k=j/i" ; break ;
}
messagebox.show(e.Message + err );
}
|
|
|
|
|
"i=0 made the exception" can be thrown by
catch(DevideByZeroException)
{
}
but I don't know how to throw "in line 5 the exception occurred" until now.
modified 27-May-14 4:55am.
|
|
|
|
|
how can warp text when writing it in txt file (using StreamReader) ?
|
|
|
|
|
I'm not sure what you mean, unless you meant "wrap" instead of "warp"?
To wrap text saved in a text file, you just insert linefeeds and/or carriage returns. But what context are you talking about? Most text editors and controls will take care of that automatically.CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
Wrap.
How can i do that please give me simple code?
|
|
|
|
|
What have you tried so far? CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
Nothing
Just search in google but no use!modified on Tuesday, March 2, 2010 1:45 AM
|
|
|
|
|
Well, try something and if it doesn't work, then come back and explain what you tried. You really haven't given enough information to help you. CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
depends.
If you're writing in a textbox or richtextbox there's a property that will do that for you.
If you want to open a bunch of text in notepad eg and you want it wrapped you can insert cairrage returns/ line feeds.
You'll have to insert those at a certain amount of characters (80 or 120 would be good)
So in pseudocode it would be like this.
chunckof_X_chars1 + Environment.NewLine + chunckof_Xchars2 + Environment.NewLine + etc...
(You should put that in a loop or something)
To be absolutely correct you should insert your crlf after the last space in the string of X chars in order to keep the words together.
This should get you going.V.
|
|
|
|
|
You can refer to the following code,it can help you.
WebRequest req = null;
WebResponse rsp = null;
try
{
string fileName = "C:\test.xml";
string uri = "http://localhost/PostXml/Default.aspx";
req = WebRequest.Create(uri);
//req.Proxy = WebProxy.GetDefaultProxy(); // Enable if using proxy
req.Method = "POST"; // Post method
req.ContentType = "text/xml"; // content type
// Wrap the request stream with a text-based writer
StreamWriter writer = new StreamWriter(req.GetRequestStream());
// Write the xml text into the stream
writer.WriteLine(this.GetTextFromXMLFile(fileName));
writer.Close();
// Send the data to the webserver
rsp = req.GetResponse();
}
catch(WebException webEx)
{
}
catch(Exception ex)
{
}
finally
{
if(req != null) req.GetRequestStream().Close();
if(rsp != null) rsp.GetResponseStream().Close();
}Function to read xml data from local system
///
/// Read xml data from file
///
/// <param name="file" />
/// <returns>returns file content in xml string format
private string GetTextFromXMLFile(string file)
{
StreamReader reader = new StreamReader(file);
string ret = reader.ReadToEnd();
reader.Close();
return ret;
}
modified 27-May-14 4:54am.
|
|
|
|
|
Was wondering if anyone knows of a workaround for the annoying memory leak in SpeechSynthesizer.
|
|
|
|
|
Don't use it?
Seriously, you're going to have to provide a link to the problem you're talking about, and there's more than one SpeechSynthesizer running around...
|
|
|
|
|
|
FocusedWolf wrote: Sorry i thought everyone knew about this
I do. But since Microsoft isn't the only vendor for speech synthesis software, I like to make sure which library we're talking about.
FocusedWolf wrote: To summarize the effect, the more words that the SpeechSynthesizer .net framework object has to read, the more megabytes of memory it consumes. It's not long before it's soaking up a few hundred mb. First effect, which sets on rather quickly, is the reader gets slower and slower.
I have tried various hacky attempts to dispose and create new objects, but it wasn't 100% successful (besides introduces a noticeable delay). This is from the first link:
I didn't use the code you linked to, but I wrote my own app and couldn't come up with a memory leak. I'm assuming the code you linked to is yours. It's written kind of funny. I'd skip destroying and creating a new synth every time you want to say something and go back to creating a single synth object you can use at any time. I'm not seeing the problem you're talking about in my code and can't find any reference to any kind of memory leak anywhere on the web.
|
|
|
|
|
No i didn't write that code... it's just a random google result from searching for other people experiencing this problem.
Anyway recently i changed the code to just use the class the way people would expect to use it (i.e. no hacky tricks to fight the memory leak) and the memory consumption was about 400 kb/s.
Some things you can try to see the effect is give the reader a few pages of words to read, and set the Rate property to some number like 7 or 10. Subscribing to these events may also be a factor (SpeakCompleted and SpeakProgress).
I've noticed that if i just let the program go then it will get to the point of holding about 40-50 mb of ram where it almost stops allocating, and a few minutes later it will get a few more mb. So i'm wondering if this is a true memory leak or by design (i.e. if it has to read a lot then it allocates all this memory). However one thing i notice is when it finished reading, it doesn't flush the memory because the program is still holding onto 46 mb.
|
|
|
|
|
If you're looking at this "used" in TaskManager, don't. Use Performance Monitor instead.
Task Manager is howing you what the .NET CLR has reserved for your app, not what your app is actually using.
|
|
|
|
|
I am actually the one who wrote the code linked to on StackOverflow. If you read the notes on this post you will see that i originally wrote the code so that it only used one instance of the SpeechSynthesizer object.
This memory leak is very much a problem with the Speak or SpeakAsync method making the System.Speech object unusable in ANY project. If you run the code you will see it will QUICKLY cause Windows 7.0 (couple hours) to crash, and will cause Vista to crash after about 20 hours.
I have both versions of the code linked here in a forum post on the MSDN site.
http://social.msdn.microsoft.com/Forums/en-US/Offtopic/thread/ee7bd34f-20c2-4a75-9d5a-a0c5e7f1a9b2[^]
|
|
|
|
|
In a forms-based application, I would like to synchronize two RichTextBox controls so that one without a vertical scroll bar will scroll in synch with the other one (which has a vertical scroll bar). I.e., I want to be able to scroll both controls with one scroll bar.
Thanks for any suggestions,
Tom
P.S. I saw Karin Huber's article, but this is for WPF and Silverlight.
|
|
|
|
|
You can build a user control (or custom control), and handle the scroll event in another RichTextBox.
April
Comm100 - Leading Live Chat Software Provider
modified 27-May-14 8:48am.
|
|
|
|
|