|
Upvoted; just knew I was listening wrong
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks for your reply, but I found the answer to my problem, elsewhere. It is "String.Format("{0} blahblah {1} years of age") and fill it in a textbox, instead of Console.WriteLine, that goes to Command Prompt.
|
|
|
|
|
That code just creates a templated string, fills it with the parameters being passed. That has nothing to do with writing to consoles, or writing to textboxes. It is just the way of building strings.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
I am not familiar with WinPhone C# programming, however, there is a general strategy I've often used to deal with a similar issue:
1. set a global flag that will determine where output goes: to Console, or TextBox
private const bool OutputToConsole = true; // true for debugging
2. in your code:
private void SomeMethod(string blah)
{
if(OutputToConsole)
{
Console.WriteLine("my blah is:" + blah);
}
else
{
someTextBox.Text = String.Format("my blah is: {0}", blah);
}
} This gets tiresome, but you can make this a bit easier to write by pre-defining template strings to use, and wrapping the whole thing up in an Extension Method for Type String:
public static class StringExtensions
{
public static bool OutputToConsole = false;
private static StringBuilder sb = new StringBuilder();
public static void WriteString(this string content, bool toconsole, TextBox tbxtarget = null, string template = "")
{
sb.Clear();
sb.Append((template == "")
? content
: String.Format(template, content));
if (OutputToConsole || toconsole || tbxtarget == null)
{
Console.WriteLine(sb.ToString());
}
else
{
tbxtarget.Text = sb.ToString();
}
}
} So, now, if I have two TextBoxes on some Form, 'textBox1, and 'textBox2, and a Button, 'button1, I can:
public const string template0 = "blah state is: {0}";
private void button1_Click(object sender, EventArgs e)
{
"medium blah".WriteString(true, template: template0);
"empty blah".WriteString(false, textBox2, template0);
} The first call to 'WriteString writes "blah state is: medium blah" to the Console, the second writes "blah state is: empty blah" to 'textBox2.
Note: I assume Windows Phone programming supports Extension Methods; if that's not the case, let me know.
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
Your WriteString extension method isn't thread-safe.
Also, there's not a lot of point using a StringBuilder if you're only going to append a single string.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
As always, thanks for the feedback, Richard.
If you care to say a few words about why it's not thread safe, I'd be grateful; I have virtually no experience dealing with multi-threaded apps, or multi-user apps.
Yes, the use of 'StringBuilder here is a bit over-kill, but the example you see here is extracted/altered from code I used where a lot more is logged, and there is a great deal more done with strings.
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
It's not thread-safe because you're sharing a single StringBuilder object, without synchronizing access to the shared state.
Imagine two threads calling WriteString at the same time. You could end up with:
T1: Clear
T2: Clear
T1: Append "Message from T1"
T2: Append "Message from T2"
T1: Output "Message from T1Message from T2"
T2: Output "Message from T1Message from T2"
Or:
T1: Clear
T1: Append "Message from T1"
T2: Clear
T2: Append "Message from T2"
T1: Output "Message from T2"
T2: Output "Message from T2"
Or:
T1: Clear
T1: Append "Message from T1"
T2: Clear
T1: Output ""
T2: Append "Message from T2"
T2: Output "Message from T2"
Or any other sequence of calls which could result in incorrect output.
Also, the StringBuilder class isn't thread-safe, so you could end up corrupting the internal state of the object and getting weird output or exceptions.
And that's before you consider the possibility that the JIT compiler is free to reorder operations if doing so doesn't change the outcome of the code on a single thread:
C# - The C# Memory Model in Theory and Practice[^]
C# - The C# Memory Model in Theory and Practice, Part 2[^]
If you really needed to use a static instance of the StringBuilder class, you'd either need to add a lock block around the access, reducing the performance of your code; or you'd need to use Thread Local Storage[^] to have a single instance of the class per thread.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Enlightening ! thanks, Bill
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
By default the GridView inplace editor has the mouse wheel handler which allows to change the data inside by scrolling the mouse wheel
Could you please suggest how to cancel the mentioned mouse wheel handler
|
|
|
|
|
You already asked this question in QA. Don't repeat the same question in multiple forums. It just hampers efforts to get a colaborated answer.
|
|
|
|
|
Hello,
I am using 'FileSystemWatcher.enableraiseevents' to get the events when a directory, or file in a directory changes. I have used FileSystemWatcher.Error to catch the errors. These are the errors logged in my system.
Exception : System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out, Hash code: 28048521, Type: System.IO.ErrorEventArgs, To string: System.IO.ErrorEventArgs
Exception : System.ComponentModel.Win32Exception (0x80004005): The operation completed successfully, Hash code: 1658455, Type: System.IO.ErrorEventArgs, To string: System.IO.ErrorEventArgs
Exception : System.ComponentModel.Win32Exception (0x80004005): Unknown error (0x490062), Hash code: 27762102, Type: System.IO.ErrorEventArgs, To string: System.IO.ErrorEventArgs
My question is what is the meaning of these errors ?
Why I am getting these errors ?
Please help me.
|
|
|
|
|
srikrishnathanthri wrote: Please help me. I'll copy/paste every answer from the same question on SO here, would that help?
--edit
To explain why I'm not so very happy with this question; imagine taking 10 minutes to write a long answer with lots o' detail - just to hear you say "I already know". You could have included a link to your question on SO so that I am not just repeating other answers.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
modified 22-Jun-16 8:08am.
|
|
|
|
|
I have given the complete information of exception which I am getting from Exception.ToString()
In this case I cant get errors in debug. It's logged in run time randomly.
I am searching at least 30 minutes before posting any questions in the forum.
|
|
|
|
|
srikrishnathanthri wrote: In this case I cant get errors in debug. It's logged in run time randomly. It may be caused by lots of messages from the OS, which aren't there as soon as you halt execution and go to debug.
FileSystemWatcher.Error Event (System.IO)[^]
The operation timed out, would mean that the OS started an operation but did not get informed of its completion; which in turn could cause the next errors. You might also want to read this[^] thread from SO.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello,
I planning to use Microsoft Enterprise library 5, for connecting Microsoft Access and perform asynchronous operations. I found that ODBC can be achieved by using GenericDatabase of Microsoft.Practices.EnterpriseLibrary.Data But in that method I am getting a error as "The database type "GenericDatabase" does not support asynchronous operations"
Is it possible to perform asynchronous operations using Microsoft.Practices.EnterpriseLibrary.Data.GenericDatabase ?
If not what are the possible alternatives for me ?
Please help me.
|
|
|
|
|
srikrishnathanthri wrote: If not what are the possible alternatives for me ? According to the documentation, you could use SQL Server.
Asynchronous data access is not supported by all ADO.NET data providers. The Database class exposes a Boolean property named SupportsAsync that you can test to check at run time if asynchronous operations are supported. If this property returns false, any asynchronous methods you call will throw an InvalidOperationException. In Enterprise Library 5.0, the only database type that supports asynchronous operation is the SqlDatabase class.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
srikrishnathanthri wrote: Is it possible to perform asynchronous operations using Microsoft.Practices.EnterpriseLibrary.Data.GenericDatabase ?
What part of
The database type "GenericDatabase" does not support asynchronous operations did you not understand?
|
|
|
|
|
hi
any one can please help me to send multiple sms
from click button with excel file attachement in c#.
|
|
|
|
|
An Excel file as an attachment to an SMS message?
Chances are really good that the excel file size will exceed the limits set by mobile providers.
|
|
|
|
|
Not to mention that SMS doesn't support attachments and the message size is limited to 256 chars.
|
|
|
|
|
Um...Are you sure?[^]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
SMS DOES support attachments. Ever send a picture over SMS? I have, lots of times.
The attachment size, at least on Verizon, is limited to 1.2MB.
|
|
|
|
|
|
Hello,
I have a requirement of getting updated/inserted values in SQL server 2008 using CLR method. I read on net that “trigger is meant for validation also”, But I am not getting how to get the incoming values ( before or after update/insert) to the SQL server using .net assembly System.Data.SqlClient , SqlDataReader method.
Is it posible to get the updated/inserted values using dll ?
Please help me.
|
|
|
|
|
|