|
Is there a Whirlpool class in .NET?
|
|
|
|
|
A what???
I take it you're talking about the Whirlpool hashing algorithm?? No, there isn't. You have to implement it yourself. You can find a Java version here[^] and convert the code.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
hi,
i have a problem concerning thread syncing with a manualresetevent. my code looks as below:
//this is a part of the callback of a receiving thread, qpt never gets null
//messageReceived is a manualresetevent
string qpt = myString.Substring(0, index);
Queue.Synchronized(this.Messages).Enqueue(qpt);
messageReceived.Set();
//and this is the code of my main thread, waiting for messages arriving in the queue
if (Queue.Synchronized(this.Messages).Count <= 0)
messageReceived.WaitOne(); //really waits (commented the .set)
Monitor.Enter(this.Messages);
string curLine = (string)(Queue.Synchronized(this.Messages).Dequeue());
messageReceived.Reset();
Monitor.Exit(this.Messages);
//...doing something with curline
when dequeuing, the element count is still 0. why? the queue isnt used anywhere else and it works with
while(true){
if (Queue.Synchronized(this.Messages).Count > 0)break;
}
instead of waitone (but takes 100%)
it seems that it takes a while until the queue recognises its new elements (does work with waitone if i place a debug point at waitone and always press play...). i also tried different combinations of monitor.enter, Queue.Synchronized with same results.
any ideas?
|
|
|
|
|
The Synchronized method returns a new synchronized Queue. Create it once and reuse it instead of creating it over and over again.
|
|
|
|
|
I dont agree.
The following code snippet gets three strings out of the queue
before it generates an exception:
Queue q=new Queue();
for (int i=0; i<3; i++) Queue.Synchronized(q).Enqueue("item"+i);
Monitor.Enter(q);
for (int i=0; i<4; i++) {
log("Count="+q.Count);
string s=(string)Queue.Synchronized(q).Dequeue();
if (s==null) log("<null>");
else log(s);
}
Monitor.Exit(q);
For me the synchronized queue works just fine (either with or without the monitor stuff).
Luc Pattyn
|
|
|
|
|
you are right. i tested it with only one synced queue and it has the same behaviour. i also tested an arraylist
lock (Messages) {
this.Messages.Add(qpt);
}
messageReceived.Set(); //one and only place where it gets signaled
--------------------------
while(true){
messageReceived.WaitOne();
//dirty fix
if (this.Messages.Count <= 0)
continue; //is called few times until count is really >0
string curLine = "";
lock (this.Messages) {
curLine = (string)(this.Messages[0]);
this.Messages.RemoveAt(0);
}
if(this.Messages.Count <= 0)
messageReceived.Reset();
/*curline action*/
}
instead of the queue with same results. the event is only signaled after something is added to the list, but if the waitone releases, often, not always, count is still 0.
am i stupid or what?!
|
|
|
|
|
I dont know what is going wrong in your code, it seems all right.
The only thing I can imagine is you could have more than one thread executing the
consumer sequence (waitOne + get Count): an Event.Set would signal ALL waiting threads
and only one of them would actually find something in the collection.
What IS executing the consumer sequence ? a timer event handler ?
And is it running on the UI thread ? How many threads are there ? etc.
If you want more help, I suggest you publish larger parts of your code.
My overall advice is to include (more) logging, so you can see what is going on.
Luc Pattyn
|
|
|
|
|
OK, you are right again. I finally found the solution. Always wondering where or what was releasing my waitone(), I realised that it must come from other instances of my class. So i thought why the heck can they? I always create a new ManualResetEvent, don't I?! The answer is yes, but it was static!
Shame on me and thanks for your answers,
vb
modified on Tuesday, December 30, 2008 5:50 PM
|
|
|
|
|
Hi!
I have a project say 'project1'. I have added some configuration sections to app.config file. The configuration sections contain initialization data for various objects. The objects read those configration information to initialize themselves. It works correctly.
But when i create a class library of this project and add it to a web application the objects become unable to read thier configuration data from app.config file.
So when i add that data to the web.config file it works fine.
But i want my objects be able to read configuration data from the app.config file. How can i do that?
Thanks.
|
|
|
|
|
Hi peshawarcoder,
To me, this sounds like a permission problem / path problem. Could you post the error that it gives ?
Cheers,
|
|
|
|
|
Class libraries cannot have config files. They are libraries of code that become part of the application project itself. Using the normal built-in methods, they must get their settting from the host applications config files, be it app.config for WinForms or web.config for ASP.NET. Outside of that, you'll have to implement your own configuration settings retrieval scheme.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thanks.
Your suggestion to implement my own configuration setting retrieval scheme will help me to a great extent. Did you mean to add configuration sections to the web.config file and provide code that my objects use to get information from their respective configuration sections in the web.config file. (I have already done this.)
But i want that there should be a separate configuration file from which objects instantiated from the classes in the class library get thier data.
|
|
|
|
|
peshawarcoder wrote: Did you mean to add configuration sections to the web.config file and provide code that my objects use to get information from their respective configuration sections in the web.config file
No. You implement your own configuration manager so that your code can specify which file to open to get configation settings. You can probably start with this[^].
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi,
I try to create a SoapExtensionAttribute, but when I try to add a web reference the SoapExtensionAttribute don't be insertede in a client proxy side, what I have to do to add the SoapExtensionAttribute in the client proxy side when I add the web refenrece.
ps.: I can't put the soapExtensionTypes in the app.config because in the current project has another web services from third-parties, and I implement a SFDE but don't work.
Any ideia?
Att.
Walter
Sorry by english
|
|
|
|
|
hi all
maybe you see software like "folder guard" or "lock file"
i want to wtite a software that hide a file and no one can see it while i unhide it.
how can do that in win XP
please help me
|
|
|
|
|
I have not seen those mentioned by you, but you can achive what you are expacting by encrypting, encoding or moving files to Isolated Storage.... There are many ways to do it...
|
|
|
|
|
Gents / Ladies,
I have a monetary value in a database that I extract. Due to this, I use decimal rather then double if I want to do any calculations later on. I run the following method :
decimal? abaCnt;
abaCnt = ((abCnt / 100) * 19);
txtBTW.Text = abaCnt.ToString();
This works fine, however the outcome is 967.9304 ... and I want it rounded off at 2 decimals : 967.93
if I use double, I can easily round it if by using :
double AA = Convert.ToDouble(this.txtBTW.Text);
double subrounded = Math.Round(AA, 2);
Is there a simple way doing this with the parameter decimal as well.
I couldn't find anything on the net that could explain to me how it's done.
Cheers,
|
|
|
|
|
The Math class has an overload of the Round method that takes a decimal and the wanted precision.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
txtBTW.Text = abaCnt.ToString( "0.00" );
|
|
|
|
|
Gents/ladies
Thank you for you prompt and swift reply. I highly appreciate it.
I don't think the Math class is actually taking decimal as a valid input but only double .
There is no conversion possible between double and decimal due to the well-known round-off problem that comes with this.
I managed to fix it another way :
decimal round = Convert.ToDecimal(abaCnt);
decimal? result = Decimal.Round(round, 2);
txtOffBTWTotaal.Text = result.ToString();
This did the trick.
Kind regards,
|
|
|
|
|
Rick van Woudenberg wrote: I don't think the Math class is actually taking decimal as a valid input but only double.
Don't think. Read.
MSDN Library: Math.Round method[^]
---
Year happy = new Year(2007);
|
|
|
|
|
Rick van Woudenberg wrote: I don't think the Math class is actually taking decimal as a valid input but only double.
"Thinking" is not allowed when you troubleshoot a problem. You either "know it" or you need to find out for sure.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
fine ...
I KNOW that the math class does not accept decimal as a parameter , only double .
Decimal.Round does ...
how's that ?
|
|
|
|
|
Rick van Woudenberg wrote: I KNOW that the math class does not accept decimal as a parameter , only double.
Upon which facts does your "knowledge" base? How come MSDN claims the opposite (Math.Round Method (Decimal, Int32)[^]) and the following code snippet compiles without any complaints?
decimal x = new decimal(5.555);
x = Math.Round(x, 2));
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Rick van Woudenberg wrote: I KNOW that the math class does not accept decimal as a parameter , only double.
Really? The .NET Framework documentation disagrees: Math.Round overloads[^].
What I said was a pirce of advice in ALL troubleshooting situations. I've been doing computer and programming work for over 21 years. What I've learned in those years is that in every single troubleshooting problem, no matter if your debugging code or trying to find the problem with a dishwasher, you MUST verify every fact you think you know to be successful at finding the problem or solution. That's why I said there is no "thinking" in troubleshooting. You either know "it" for a fact because you have the proof to back it up, or you don't know "it" and your guessing or making assumptions that are, far more often than not, incorrect.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|