|
CDP1802 wrote: In the end I need some safe way to raise the GetSomeEntityBySomeParameterFinished event, so that its event handler is executed by the same thread that requested the data. I'm very careful here because pulling a thread away from what it is currently doing and making it do something else instead (if that's possible at all) is just asking for even more trouble
Everything is possible; a thread is usually a loop with work, until work is done and the thread exits. You could have a check inside that loop that checks for certain conditions or events and have it act.
There's various ways to have the thread check for conditions (like a thread-safe flag), but you might want to AutoResetEvent[^] class.
Bastard Programmer from Hell
|
|
|
|
|
As it seems, the System.Windows.Threading.Dispatcher class was designed just for such a case. It allows to raise an event that then is handled on the thread that the Dispatcher was created for. MSDN did not provide too many details, but it appears that pending events are put into a queue and the thread checks the queue and calls the event handlers. There we basically have the thread's loop that does the checking, hidden away in the framework so that the application does not need to take care of any details.
The problem is that this class is in a WPF namespace. It would work, but then I would lose the option to target other framework versions and platforms where the WPF namespaces don't exist. Two candidates would have been WinPhone 7 and the XBox. But why did they put this class into the WPF namespaces? It would be really helpful in many other cases, not just when some UI is involved.
And I still think that the complete loss of control over which thread gets to execute a callback for an asynchronous operation is very problematic. It's a real complication to make all classes that need to call to the webservice thread safe.
I'm invincible, I can't be vinced
|
|
|
|
|
CDP1802 wrote: The problem is that this class is in a WPF namespace. It would work, but then I would lose the option to target other framework versions and platforms where the WPF namespaces don't exist.
Do you have Reflector or ILSpy installed? If yes, then it's always worthwhile to see if you can reimplement it in a separate assembly (meaning, if it's a simple thing without too much references)
Bastard Programmer from Hell
|
|
|
|
|
Have you investigated the BackgroundWorker class?
BackgroundWorker Class[^]
"It's not what you don't know that will hurt you the most, it's what you think you know that isn't so." - Unknown
|
|
|
|
|
I tried to format a double using ToString("f2", System.Globalization.NumberFormatInfo.CurrentInfo) . The NumberGroupSeparator is a single space, the NumberDecimalSeparator is a comma.
Hence I'd expect 3501.30 to be formatted as 3 501,30 , but I get 3501,30 (i.e. the space after thousands is missing).
It is in a C# WPF application (value is not bound to a control, but to be writte to a text file) with .NET 4 on a Win 7 64 bit (German) OS.
Is that a bug in the framework, or must I use some tricks?
|
|
|
|
|
Bernhard Hiller wrote: Is that a bug in the framework
"SELECT" isn't broken.
You're formatting it as a fixed point number. Try the one below;
static void Main(string[] args)
{
Console.WriteLine(
3501.23.ToString("N2", System.Globalization.NumberFormatInfo.CurrentInfo));
Console.ReadKey();
}
Bastard Programmer from Hell
|
|
|
|
|
Thanks! What a difference...
|
|
|
|
|
You're welcome
|
|
|
|
|
|
I am trying to write a program to select a feature using mouse click on a map control of DotSpatial framework. But I am stuck.
Please Help..
Thanks.
|
|
|
|
|
I am pretty sure that DotSpatial has a forum. I guess that's a great place to find an expert in it.
|
|
|
|
|
I recently wrote some code to clean up user input by turning all multiple-space spaces into single-space spaces.
I tried several different approaches to optimize performance, and, interestingly enough, the stringbuilder is performing better than I remember from past versions. I can't seem to do better than the following no matter how hard I try to optimize.
private StringBuilder builder = new StringBuilder();
public string RemoveExtraSpaces(string inputString)
{
builder.Clear();
int length = inputString.Length;
if (length > 0)
{
builder.Append(inputString[0]);
for (int loop1 = 1; loop1 < length; loop1++)
if (inputString[loop1 - 1] != ' ' || inputString[loop1] != ' ')
builder.Append(inputString[loop1]);
}
return builder.ToString();
}
Even for very short strings, this solution performs better than other solutions.
Edit: Also, for clarification, the RemoveExtraSpaces method is called many times in a row on a bunch of strings for performance testing.
|
|
|
|
|
The Clear() is a new method for StringBuilder in VS2010. But by observing its IL code we can see it just set this.Length = 0. So we can see that the inner algorithm somewhat not change a lot. StringBuilder is a efficient class, not only in VS 2010, I think it's the class itself rather than the IDE version that makes your solution better.
Dynamsoft
|
|
|
|
|
so_soul wrote: The Clear() is a new method for StringBuilder in VS2010
The method is new in .NET Framework 4.0, not Visual Studio 2010. Visual Studio can make use of multiple frameworks and is independent of them.
Failure is not an option; it's the default selection.
|
|
|
|
|
Curious. What else have you tried?
* String.Replace?
* RegEx.Replace?
* StringBuilder.Replace?
* Using an array of characters?
Perhaps this will give me a research topic for the day, being slow here.
|
|
|
|
|
I tried several variants of using the string concatenation += operator, stringbuilder, and arrays of characters. I expected an array of character approach to be best, but every approach I tried was slightly outperformed by the stringbuilder-based method I posted.
I didn't bother using RegEx, as I expected its overhead costs to eliminate itself here, but I could be wrong.
|
|
|
|
|
I just want to know there whether are any new files in the FTP site, and if a new file be uploaded/Deleted in the FTP site, then I will download/delete this file to local system. Could someone give me some suggestions?
|
|
|
|
|
It depends on whether or not you have control of the FTP site as well. If you do, have a process monitor that directory at that end, and maintain a hash of all the files in the FTP directory/subdirectories. Keep a hash of the files at your end, and when you connect to the FTP site, retrieve the remote hash. Compare it to yours - if it's changed, you've got changes to download.
|
|
|
|
|
Hi! I develop in Visual Studio and I need to build a SIP webphone. I searched and found a SIP softphone solution with a free sample program on the net: www.voip-sip-sdk.com/p_83-silverlight-sip-softphone-javascript-voip.html (I added this site for showing you the example program I found on the net.) Is it possible to build a Silverlight SIP softphone in both Visual Studio 2008 and 2010 ? Thank you for your answer.
|
|
|
|
|
In the .NET Framework, what exception would you expect Image.FromFile to throw if the image is invalid? Something like an "InvalidImageFormatException" or similar?
Nope. It throws an OutOfMemoryException. MSDN says:
OutOfMemoryException
The file does not have a valid image format.
-or-
GDI+ does not support the pixel format of the file.
Really? I doubt the system is actually running out of memory as it returns quickly.
|
|
|
|
|
It does what the documentation says it does. That is positive in general, and it sounds a bit weird in this case.
Anyhow, it is a lot better than getting a "General error occurred in GDI+" which can mean almost anything.
|
|
|
|
|
You are probably trying to read an image that is not valid.
If you notice, there is no such exception like "Invalid Image" listed out.
OutOfMemoryException
The file does not have a valid image format.
-or-
GDI+ does not support the pixel format of the file.
FileNotFoundException
The specified file does not exist.
ArgumentException
filename is a Uri.
|
|
|
|
|
Yeah, I'm validating that an uploaded image is actually a valid image. I was just ranting about the framework using an OutOfMemoryException to signal an exception that doesn't relate to memory at all
|
|
|
|
|
Daniel Lo Nigro wrote: I was just ranting about the framework using an OutOfMemoryException to
signal an exception that doesn't relate to memory at all
Not necessarily true. It could be a bug in GDI+ that recursively tries to load the bad image and results in a real Out of Memory situation.
|
|
|
|
|
How to convert string english to marathi
|
|
|
|